File size: 7,084 Bytes
4eb44b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Run:  node tests/test_compose.js   (from the space/ directory)
const fs = require("fs");
const path = require("path");
const vm = require("vm");
const root = path.join(__dirname, "..");

// Load the browser data files into a sandbox that mimics `window`.
const win = {};
for (const f of ["data/gaidet.js", "data/templates.js"]) {
  vm.runInNewContext(fs.readFileSync(path.join(root, f), "utf8"), { window: win });
}
const C = require(path.join(root, "compose.js"));
const D = win.GAIDET, T = win.TEMPLATES;

let failed = 0;
function eq(name, got, want) {
  if (got === want) { console.log("ok   " + name); return; }
  failed++;
  console.log("FAIL " + name + "\n   got:  " + JSON.stringify(got) + "\n   want: " + JSON.stringify(want));
}

const base = { used: true, style: "document", tasks: [], tools: ["Claude Opus 5.5"], party: "the authors", partyId: "authors", plural: true, work: "report", workId: "report", review: true, cite: false, rollup: false };
const S = (o) => Object.assign({}, base, o);

// joinList
eq("join 1", C.joinList(["a"]), "a");
eq("join 2", C.joinList(["a", "b"]), "a and b");
eq("join 3 oxford", C.joinList(["a", "b", "c"]), "a, b, and c");
eq("join inner and -> semicolons", C.joinList(["x and y", "z"]), "x and y; and z");
eq("join 3 with inner and", C.joinList(["x and y", "b", "c"]), "x and y; b; and c");
eq("join and/or", C.joinList(["market and/or patent", "b"]), "market and/or patent; and b");

// The user's own case: 0000017, 0000018, 0000020, 0000037
const mine = ["0000017", "0000018", "0000020", "0000037"];
eq("document, user's case",
  C.compose(S({ tasks: mine }), D, T).text,
  "Generative AI (Claude Opus 5.5) was used for code generation; code optimization; creation of algorithms for data analysis; and preparation of press releases and outreach materials. All AI-generated material was reviewed, tested, and validated by the authors, who take full responsibility for the content.");
eq("slide, user's case",
  C.compose(S({ tasks: mine, style: "slide" }), D, T).text,
  "AI use: code generation, code optimization, data-analysis algorithms, and outreach materials (Claude Opus 5.5); reviewed and validated by the authors.");
eq("minimal, user's case",
  C.compose(S({ tasks: mine, style: "minimal" }), D, T).text,
  "AI-assisted (Claude Opus 5.5): code generation, code optimization, data-analysis algorithms, and outreach materials.");

// Order follows the taxonomy, not selection order
eq("taxonomy order", C.compose(S({ tasks: ["0000035", "0000017"], style: "minimal" }), D, T).text,
  "AI-assisted (Claude Opus 5.5): code generation and translation.");

// Singular party
eq("singular verb", C.compose(S({ tasks: ["0000031"], party: "the author", plural: false }), D, T).text,
  "Generative AI (Claude Opus 5.5) was used for proofreading and editing. All AI-generated material was reviewed and revised as needed by the author, who takes full responsibility for the content.");

// No tools, no review, cite on
eq("no tools + cite, no review", C.compose(S({ tasks: ["0000035"], tools: [], review: false, cite: true }), D, T).text,
  "Generative AI was used for translation (tasks classified according to the GAIDeT taxonomy, Suchikova et al. 2026).");

// Two tools
eq("two tools", C.compose(S({ tasks: ["0000035"], tools: ["ChatGPT", "Claude"], style: "minimal" }), D, T).text,
  "AI-assisted (ChatGPT and Claude): translation.");

// Rollup
eq("rollup document", C.compose(S({ tasks: mine, rollup: true, review: false }), D, T).text,
  "Generative AI (Claude Opus 5.5) was used for software development and automation; and writing and editing.");
eq("rollup slide", C.compose(S({ tasks: mine, rollup: true, style: "slide", review: false }), D, T).text,
  "AI use: software development; and writing and editing (Claude Opus 5.5).");

// Slide with cite
eq("slide cite", C.compose(S({ tasks: ["0000035"], style: "slide", cite: true }), D, T).text,
  "AI use: translation (Claude Opus 5.5); reviewed by the authors; GAIDeT taxonomy.");

// No AI used
eq("none document", C.compose(S({ used: false, work: "presentation" }), D, T).text, "No generative AI was used in preparing this presentation.");
eq("none minimal", C.compose(S({ used: false, style: "minimal" }), D, T).text, "No AI used.");

// Empty selection
const e = C.compose(S({ tasks: [] }), D, T);
eq("empty not ok", e.ok, false);

// URL round trip
const st = S({ tasks: mine, style: "slide", partyId: "custom", party: "IFPRI staff", plural: true, workId: "custom", work: "policy note", review: false, cite: true, rollup: true });
const back = C.fromParams(new URLSearchParams(C.toParams(st).toString()));
eq("url tasks", back.tasks.join(","), mine.join(","));
eq("url style", back.style, "slide");
eq("url tools", back.tools.join("|"), "Claude Opus 5.5");
eq("url party", back.party, "IFPRI staff");
eq("url work", back.work, "policy note");
eq("url review", back.review, false);
eq("url cite", back.cite, true);
eq("url rollup", back.rollup, true);
eq("url none", C.fromParams(C.toParams(S({ used: false }))).used, false);
eq("default url is empty", C.toParams(S({ tasks: [], tools: [], workId: "document", work: "document" })).toString(), "");

// Technical clause triggers
eq("technical: methodology", C.isTechnical(D, T, ["0000013"]), true);
eq("technical: data", C.isTechnical(D, T, ["0000026"]), true);
eq("not technical: writing + ethics", C.isTechnical(D, T, ["0000035", "0000040"]), false);
eq("slide non-technical review", C.compose(S({ tasks: ["0000035"], style: "slide" }), D, T).text,
  "AI use: translation (Claude Opus 5.5); reviewed by the authors.");

// Notes
const N = (o) => C.notes(S(o), D, T);
eq("notes: methods only", N({ tasks: ["0000017"] }).join("|"), T.placement.methods);
eq("notes: ack only", N({ tasks: ["0000031"] }).join("|"), T.placement.acknowledgements);
eq("notes: publication support counts as ack", N({ tasks: ["0000048"] }).join("|"), T.placement.acknowledgements);
eq("notes: both", N({ tasks: mine }).join("|"), T.placement.both);
eq("notes: manuscript adds journal note", N({ tasks: ["0000017"], workId: "manuscript" }).join("|"), T.placement.methods + "|" + T.journalNote);
eq("notes: manuscript, no AI", N({ used: false, workId: "manuscript" }).join("|"), T.journalNote);
eq("notes: blog routine only", N({ tasks: ["0000031", "0000035"], workId: "blog post" }).join("|"), T.routineNote);
eq("notes: blog substantive", N({ tasks: ["0000030", "0000035"], workId: "blog post" }).join("|"), "");
eq("notes: code work type", N({ tasks: ["0000017"], workId: "code" }).join("|"), "");
eq("notes: custom work type", N({ tasks: ["0000017"], workId: "custom", work: "policy note" }).join("|"), "");
eq("notes: no AI, report", N({ used: false }).join("|"), "");

// Every term has a short label and resolvable-looking URI
let n = 0;
D.groups.forEach(g => g.terms.forEach(t => { n++; if (!t.short || !/^https:\/\/w3id\.org\/gaidet\/\d{7}$/.test(t.uri)) { failed++; console.log("FAIL term " + t.id); } }));
eq("40 terms", n, 40);

console.log(failed ? `\n${failed} test(s) FAILED` : "\nAll tests passed");
process.exit(failed ? 1 : 0);