artifacts.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /**
  2. * 用户面产物(docs/dynamic-workflow/authoring.md)的编译侧:站点身份、lowering、编译期诊断与
  3. * `declaredArtifacts` 清单。引擎侧在 tests/engine/engine-artifacts.test.ts。
  4. *
  5. * ⚠ 术语:本文件的 artifact 一律指**用户面产物**(脚本发布给用户看的产出),不是引擎内部
  6. * 同名的顶层返回值(`RunSettlement.artifact`)。
  7. */
  8. import { describe, expect, it } from "vitest";
  9. import {
  10. analyzeWorkflowScript,
  11. ARTIFACT_DECLARATION_CODE,
  12. ARTIFACT_HOISTING_CODE,
  13. ARTIFACT_PRIMARY_CONFLICT_CODE,
  14. collectArtifactDeclarations,
  15. collectDiagnostics,
  16. collectSites,
  17. createWorkflowProgram,
  18. lowerWorkflow,
  19. } from "../src/index.js";
  20. import { FACADE_SITING_CODE } from "../src/analysis/facade-misuse.js";
  21. const CHART = '{ x: { field: "round" }, y: { field: "ms" } }';
  22. /** 编译 + 收集站点(脚本必须先干净通过 typecheck——否则站点表不可信)。 */
  23. function sites(scriptText: string) {
  24. const workflow = createWorkflowProgram(scriptText);
  25. expect(collectDiagnostics(workflow.program)).toEqual([]);
  26. return { table: collectSites(workflow), workflow };
  27. }
  28. function lower(scriptText: string): string {
  29. const { table, workflow } = sites(scriptText);
  30. return lowerWorkflow(workflow, table).code;
  31. }
  32. /** 只取产物相关的三个诊断码(其余 authoring 诊断不在本文件的射程内)。 */
  33. function artifactDiagnostics(scriptText: string) {
  34. const analyzed = analyzeWorkflowScript(scriptText);
  35. return analyzed.diagnostics.filter(
  36. (d) =>
  37. d.code === ARTIFACT_DECLARATION_CODE ||
  38. d.code === ARTIFACT_HOISTING_CODE ||
  39. d.code === ARTIFACT_PRIMARY_CONFLICT_CODE,
  40. );
  41. }
  42. describe("artifact sites", () => {
  43. it("mints one site per member with the registry op, on its own counter", () => {
  44. const { table } = sites(
  45. [
  46. `artifact.chart("perf", ${CHART});`,
  47. `artifact.table("rows", { columns: [{ field: "name" }] });`,
  48. `artifact.metrics("m", { metrics: [{ field: "p95" }] });`,
  49. `artifact.board("b", { key: "id", status: "state", columns: ["todo"] });`,
  50. `await artifact.file("book", "out/book.pdf");`,
  51. `await artifact.markdown("notes", "# hi");`,
  52. ].join("\n"),
  53. );
  54. expect(table.artifacts.map((site) => [site.id, site.op, site.artifactId])).toEqual([
  55. ["artifact#1", "chart", "perf"],
  56. ["artifact#2", "table", "rows"],
  57. ["artifact#3", "metrics", "m"],
  58. ["artifact#4", "board", "b"],
  59. ["artifact#5", "file", "book"],
  60. ["artifact#6", "markdown", "notes"],
  61. ]);
  62. });
  63. // site-id stability:加产物调用不得挪动任何既有 id(journal 的键就是这些 id)。
  64. it("leaves ask/actor/report/world-read ids byte-identical", () => {
  65. const withoutArtifacts = [
  66. `const a = agent("w");`,
  67. `const files1 = await files.glob("*.ts");`,
  68. `report({ n: files1.length });`,
  69. `const r = await a.ask("go");`,
  70. `return r;`,
  71. ].join("\n");
  72. const withArtifacts = [
  73. `const a = agent("w");`,
  74. `artifact.chart("perf", ${CHART});`,
  75. `const files1 = await files.glob("*.ts");`,
  76. `report({ n: files1.length }, "perf");`,
  77. `await artifact.markdown("notes", "# hi");`,
  78. `const r = await a.ask("go");`,
  79. `return r;`,
  80. ].join("\n");
  81. const idsOf = (text: string) => {
  82. const { table } = sites(text);
  83. return [
  84. ...table.actors.map((s) => s.id),
  85. ...table.asks.map((s) => s.id),
  86. ...table.reports.map((s) => s.id),
  87. ...table.worldReads.map((s) => s.id),
  88. ];
  89. };
  90. expect(idsOf(withArtifacts)).toEqual(idsOf(withoutArtifacts));
  91. });
  92. it("collects the report tag as a literal, and keeps a non-literal one raw", () => {
  93. const { table } = sites(
  94. [
  95. `artifact.chart("perf", ${CHART});`,
  96. `const tag = "perf";`,
  97. `report({ a: 1 }, "perf");`,
  98. `report({ a: 2 }, tag);`,
  99. `report({ a: 3 });`,
  100. ].join("\n"),
  101. );
  102. expect(table.reports.map((s) => s.artifactId)).toEqual(["perf", undefined, undefined]);
  103. // 非字面量标签有表达式、无值;无标签两者皆无——诊断趟据此区分「写错了」与「没写」。
  104. expect(table.reports.map((s) => s.artifactIdExpr !== undefined)).toEqual([true, true, false]);
  105. });
  106. it("consumes the global discovery order alongside report sites", () => {
  107. const { table, workflow } = sites(
  108. [`report({ a: 1 });`, `artifact.chart("perf", ${CHART});`, `report({ a: 2 }, "perf");`].join(
  109. "\n",
  110. ),
  111. );
  112. expect(lowerWorkflow(workflow, table).siteIds).toEqual(["report#1", "artifact#1", "report#2"]);
  113. });
  114. });
  115. describe("artifact lowering", () => {
  116. it("lowers content members to __host.publishArtifact with positional args", () => {
  117. const code = lower(
  118. `await artifact.file("book", "out/book.pdf", { title: "Book" });\n` +
  119. `await artifact.markdown("notes", "# hi");`,
  120. );
  121. expect(code).toContain(
  122. `__host.publishArtifact("artifact#1", "file", ["book", "out/book.pdf", { title: "Book" }])`,
  123. );
  124. expect(code).toContain(`__host.publishArtifact("artifact#2", "markdown", ["notes", "# hi"])`);
  125. });
  126. it("lowers preset members to __host.declareArtifact", () => {
  127. const code = lower(`artifact.chart("perf", ${CHART});`);
  128. expect(code).toContain(`__host.declareArtifact("artifact#1", "chart", ["perf", {`);
  129. expect(code).not.toContain("publishArtifact");
  130. });
  131. it("passes the report tag through as a third argument", () => {
  132. const code = lower(
  133. `artifact.chart("perf", ${CHART});\nreport({ a: 1 }, "perf");\nreport({ a: 2 });`,
  134. );
  135. expect(code).toContain(`__host.report("report#1", { a: 1 }, "perf")`);
  136. expect(code).toContain(`__host.report("report#2", { a: 2 })`);
  137. });
  138. it("leaves log and phase on their own host members", () => {
  139. const code = lower(`phase("gate");\nlog("hi");\nawait artifact.markdown("n", "x");`);
  140. expect(code).toContain("__host.log(");
  141. // 标记不再抹成 void 0:它改写成 enterPhase(docs/execution-engine.md「From script to sandbox input: lowering」)。
  142. expect(code).toContain('__host.enterPhase("gate")');
  143. expect(code).toContain("__host.publishArtifact(");
  144. });
  145. it("keeps artifact sites in the lowered site id list", () => {
  146. const { table, workflow } = sites(`await artifact.file("book", "b.pdf");`);
  147. expect(lowerWorkflow(workflow, table).siteIds).toEqual(["artifact#1"]);
  148. });
  149. });
  150. describe("artifact id diagnostics", () => {
  151. it("rejects a non-literal id, positioned on the argument", () => {
  152. const diagnostics = artifactDiagnostics(
  153. `const id = "book";\nawait artifact.file(id, "b.pdf");`,
  154. );
  155. expect(diagnostics).toHaveLength(1);
  156. expect(diagnostics[0]?.code).toBe(ARTIFACT_DECLARATION_CODE);
  157. expect(diagnostics[0]?.line).toBe(2);
  158. expect(diagnostics[0]?.message).toContain("compile-time string literal");
  159. });
  160. it("rejects a substitution-template id", () => {
  161. expect(
  162. artifactDiagnostics('const n = 1;\nawait artifact.file(`book-${n}`, "b.pdf");'),
  163. ).toHaveLength(1);
  164. });
  165. it("rejects an empty id", () => {
  166. const diagnostics = artifactDiagnostics(`await artifact.file("", "b.pdf");`);
  167. expect(diagnostics[0]?.message).toContain("must not be empty");
  168. });
  169. it("rejects an over-long id", () => {
  170. const id = "x".repeat(65);
  171. const diagnostics = artifactDiagnostics(`await artifact.file("${id}", "b.pdf");`);
  172. expect(diagnostics[0]?.message).toContain("the limit is 64");
  173. });
  174. it("rejects illegal characters", () => {
  175. const diagnostics = artifactDiagnostics(`await artifact.file("out/book pdf", "b.pdf");`);
  176. expect(diagnostics[0]?.message).toContain("[A-Za-z0-9_.-]");
  177. });
  178. it("accepts the legal character set", () => {
  179. expect(artifactDiagnostics(`await artifact.file("perf.p95_v2-final", "b.pdf");`)).toEqual([]);
  180. });
  181. it("rejects one id used with two kinds, pointing at the second", () => {
  182. const diagnostics = artifactDiagnostics(
  183. `await artifact.file("x", "b.pdf");\nawait artifact.markdown("x", "hi");`,
  184. );
  185. expect(diagnostics).toHaveLength(1);
  186. expect(diagnostics[0]?.line).toBe(2);
  187. expect(diagnostics[0]?.message).toContain("two different kinds");
  188. });
  189. it("allows the same id republished with the same kind (that is a new version)", () => {
  190. expect(
  191. artifactDiagnostics(`await artifact.file("x", "a.pdf");\nawait artifact.file("x", "b.pdf");`),
  192. ).toEqual([]);
  193. });
  194. });
  195. describe("primary diagnostics (9009)", () => {
  196. it("rejects two different ids both marked primary, positioned on the second flag", () => {
  197. const diagnostics = artifactDiagnostics(
  198. `await artifact.file("book", "b.pdf", { primary: true });\n` +
  199. `await artifact.markdown("notes", "hi", { title: "Notes",\n primary: true });`,
  200. );
  201. expect(diagnostics).toHaveLength(1);
  202. expect(diagnostics[0]?.code).toBe(ARTIFACT_PRIMARY_CONFLICT_CODE);
  203. expect(diagnostics[0]?.line).toBe(3);
  204. expect(diagnostics[0]?.message).toContain('"book" already is');
  205. });
  206. it("counts a preset's spec flag too", () => {
  207. const diagnostics = artifactDiagnostics(
  208. `artifact.board("b", { key: "id", status: "s", columns: ["x"], primary: true });\n` +
  209. `await artifact.file("book", "b.pdf", { primary: true });`,
  210. );
  211. expect(diagnostics.map((d) => d.code)).toEqual([ARTIFACT_PRIMARY_CONFLICT_CODE]);
  212. });
  213. it("allows the same id flagged twice (a new version of the deliverable)", () => {
  214. expect(
  215. artifactDiagnostics(
  216. `await artifact.file("x", "a.pdf", { primary: true });\nawait artifact.file("x", "b.pdf", { primary: true });`,
  217. ),
  218. ).toEqual([]);
  219. });
  220. it("ignores a computed or false flag — that half belongs to the engine", () => {
  221. expect(
  222. artifactDiagnostics(
  223. `const p = true;\nawait artifact.file("a", "a.pdf", { primary: p });\n` +
  224. `await artifact.file("b", "b.pdf", { primary: true });\nawait artifact.file("c", "c.pdf", { primary: false });`,
  225. ),
  226. ).toEqual([]);
  227. });
  228. });
  229. describe("preset hoisting diagnostics", () => {
  230. it("rejects a preset declared in a loop body", () => {
  231. const diagnostics = artifactDiagnostics(
  232. `for (const p of ["a"]) {\n artifact.chart("perf", ${CHART});\n}`,
  233. );
  234. expect(diagnostics).toHaveLength(1);
  235. expect(diagnostics[0]?.code).toBe(ARTIFACT_HOISTING_CODE);
  236. expect(diagnostics[0]?.message).toContain("inside a loop");
  237. });
  238. it("rejects a preset declared inside a callback", () => {
  239. const diagnostics = artifactDiagnostics(
  240. `["a"].forEach(() => {\n artifact.table("rows", { columns: [{ field: "n" }] });\n});`,
  241. );
  242. expect(diagnostics[0]?.code).toBe(ARTIFACT_HOISTING_CODE);
  243. expect(diagnostics[0]?.message).toContain("inside a callback");
  244. });
  245. it("rejects a preset declared inside a conditional branch", () => {
  246. const diagnostics = artifactDiagnostics(
  247. `if (args.deep) {\n artifact.metrics("m", { metrics: [{ field: "p95" }] });\n}`,
  248. );
  249. expect(diagnostics[0]?.code).toBe(ARTIFACT_HOISTING_CODE);
  250. expect(diagnostics[0]?.message).toContain("conditional branch");
  251. });
  252. // 回归(2026-09-29 testfield 实测):补全的函数体被拼进 `hole(name, prompt, async () => {…})` 的箭头里,
  253. // 旧规则把一切箭头都当回调,于是任何补全都声明不了看板——主代理只好放弃那块看板。
  254. const BOARD = '{ key: "module", status: "status", columns: ["done", "concerns"] }';
  255. it("lets a fill declare a preset: the hole's body runs where the hole stands", () => {
  256. expect(
  257. artifactDiagnostics(
  258. `return await hole<number>("第1步:施工", "p", async () => {\n` +
  259. ` artifact.board("modules", ${BOARD});\n` +
  260. ` report({ module: "lexer", status: "done" }, "modules");\n` +
  261. ` return 1;\n` +
  262. `});`,
  263. ),
  264. ).toEqual([]);
  265. });
  266. it("lets a fill nested in a tail chain declare a preset too", () => {
  267. expect(
  268. artifactDiagnostics(
  269. `return await hole<number>("第1步:施工", "p", async () => {\n` +
  270. ` return await hole<number>("第2步:验收", "q", async () => {\n` +
  271. ` artifact.chart("perf", ${CHART});\n` +
  272. ` return 2;\n` +
  273. ` });\n` +
  274. `});`,
  275. ),
  276. ).toEqual([]);
  277. });
  278. it("still sees the loop around a hole whose fill declares a preset", () => {
  279. const diagnostics = artifactDiagnostics(
  280. `for (const p of ["a", "b"]) {\n` +
  281. ` await hole<void>("每轮怎么做", p, async () => {\n` +
  282. ` artifact.board("modules", ${BOARD});\n` +
  283. ` });\n` +
  284. `}`,
  285. );
  286. expect(diagnostics.map((d) => d.code)).toEqual([ARTIFACT_HOISTING_CODE]);
  287. expect(diagnostics[0]?.message).toContain("inside a loop");
  288. });
  289. it("still flags a real callback inside a fill", () => {
  290. const diagnostics = artifactDiagnostics(
  291. `return await hole<number>("第1步:施工", "p", async () => {\n` +
  292. ` ["a"].forEach(() => {\n artifact.board("modules", ${BOARD});\n });\n` +
  293. ` return 1;\n` +
  294. `});`,
  295. );
  296. expect(diagnostics.map((d) => d.code)).toEqual([ARTIFACT_HOISTING_CODE]);
  297. expect(diagnostics[0]?.message).toContain("inside a callback");
  298. });
  299. it("leaves content members alone in loops and branches (a new version per round is the point)", () => {
  300. expect(
  301. artifactDiagnostics(
  302. `for (const p of ["a"]) {\n await artifact.file("book", "b.pdf");\n}\n` +
  303. `if (args.x) { await artifact.markdown("notes", "hi"); }`,
  304. ),
  305. ).toEqual([]);
  306. });
  307. it("accepts a top-level preset declaration fed from inside a loop", () => {
  308. expect(
  309. artifactDiagnostics(
  310. `artifact.chart("perf", ${CHART});\nfor (const p of ["a"]) {\n report({ round: 1 }, "perf");\n}`,
  311. ),
  312. ).toEqual([]);
  313. });
  314. });
  315. describe("report tag diagnostics", () => {
  316. it("rejects a non-literal tag", () => {
  317. const diagnostics = artifactDiagnostics(
  318. `artifact.chart("perf", ${CHART});\nconst t = "perf";\nreport({ a: 1 }, t);`,
  319. );
  320. expect(diagnostics).toHaveLength(1);
  321. expect(diagnostics[0]?.line).toBe(3);
  322. expect(diagnostics[0]?.message).toContain("compile-time string literal");
  323. });
  324. it("rejects a tag naming no declared preset, and lists the ones that exist", () => {
  325. const diagnostics = artifactDiagnostics(
  326. `artifact.chart("perf", ${CHART});\nreport({ a: 1 }, "nope");`,
  327. );
  328. expect(diagnostics).toHaveLength(1);
  329. expect(diagnostics[0]?.message).toContain('declared presets: "perf"');
  330. });
  331. it("says so plainly when the script declares no presets at all", () => {
  332. const diagnostics = artifactDiagnostics(`report({ a: 1 }, "perf");`);
  333. expect(diagnostics[0]?.message).toContain("no preset artifacts at all");
  334. });
  335. it("rejects a tag naming a content artifact", () => {
  336. const diagnostics = artifactDiagnostics(
  337. `await artifact.markdown("doc", "# hi");\nreport({ a: 1 }, "doc");`,
  338. );
  339. expect(diagnostics).toHaveLength(1);
  340. expect(diagnostics[0]?.message).toContain("holds content rather than a stream of items");
  341. });
  342. it("accepts a tag declared later in the text (order is a run-time matter)", () => {
  343. expect(
  344. artifactDiagnostics(`report({ a: 1 }, "perf");\nartifact.chart("perf", ${CHART});`),
  345. ).toEqual([]);
  346. });
  347. it("leaves untagged reports alone", () => {
  348. expect(artifactDiagnostics(`report({ a: 1 });`)).toEqual([]);
  349. });
  350. });
  351. describe("declaredArtifacts", () => {
  352. it("is deduplicated and sorted by id", () => {
  353. const analyzed = analyzeWorkflowScript(
  354. [
  355. `artifact.chart("perf", ${CHART});`,
  356. `artifact.chart("perf", ${CHART});`,
  357. `await artifact.file("book", "b.pdf");`,
  358. `await artifact.file("book", "b2.pdf");`,
  359. `artifact.board("kanban", { key: "id", status: "s", columns: ["a"] });`,
  360. ].join("\n"),
  361. );
  362. expect(analyzed.ok).toBe(true);
  363. expect(analyzed.declaredArtifacts).toEqual([
  364. { id: "book", kind: "file" },
  365. { id: "kanban", kind: "board" },
  366. { id: "perf", kind: "chart" },
  367. ]);
  368. });
  369. it("is empty for a script with no artifacts, and for one that does not compile", () => {
  370. expect(analyzeWorkflowScript(`log("hi");`).declaredArtifacts).toEqual([]);
  371. expect(analyzeWorkflowScript(`const x: number = "no";`).declaredArtifacts).toEqual([]);
  372. });
  373. it("comes straight off the site table, so collectArtifactDeclarations is usable alone", () => {
  374. const { table, workflow } = sites(`await artifact.file("book", "b.pdf");`);
  375. const { declaredArtifacts, diagnostics } = collectArtifactDeclarations(workflow, table);
  376. expect(diagnostics).toEqual([]);
  377. expect(declaredArtifacts).toEqual([{ id: "book", kind: "file" }]);
  378. });
  379. });
  380. /**
  381. * 诊断的**去处**(2026-09-04 裁决):产物诊断必须与 world.run 的非字面量 cmd 走**同一条**
  382. * authoring 通道——也就是 `analyzeWorkflowScript` 的 `{ ok, diagnostics }`。
  383. *
  384. * 那条通道有三个消费方,都在 core 侧读同一个 `analyzeScript(...)`:CreateWorkflow handler
  385. * (`!ok` ⇒ 把每条诊断渲染成 `L{line}:C{column} {message}` 回给模型自修,且**不执行**)、
  386. * SaveWorkflow(`!ok` ⇒ 不落盘)、以及中枢直接启动(`!ok || diagnostics.length > 0` ⇒
  387. * compile_failed)。所以"被收集到了"不等于"被看见了":`ok` 必须被清掉,诊断必须带位置。
  388. * 本组用例把这两件事与 world.run 的先例并排钉住。
  389. */
  390. describe("authoring diagnostics channel", () => {
  391. const BAD_ARTIFACT = `const id = "book";\nawait artifact.file(id, "b.pdf");`;
  392. const BAD_WORLD_RUN = `const cmd = "lean";\nawait world.run(cmd, []);`;
  393. it("clears ok and surfaces the diagnostic, exactly like a non-literal world.run cmd", () => {
  394. const artifactRun = analyzeWorkflowScript(BAD_ARTIFACT);
  395. const worldRun = analyzeWorkflowScript(BAD_WORLD_RUN);
  396. expect(artifactRun.ok).toBe(worldRun.ok);
  397. expect(artifactRun.ok).toBe(false);
  398. expect(artifactRun.diagnostics).toHaveLength(1);
  399. expect(artifactRun.diagnostics[0]?.code).toBe(ARTIFACT_DECLARATION_CODE);
  400. });
  401. it("positions every artifact diagnostic, so the model-facing render has a line and column", () => {
  402. const scripts = [
  403. BAD_ARTIFACT,
  404. `await artifact.file("", "b.pdf");`,
  405. `await artifact.file("a b", "b.pdf");`,
  406. `await artifact.file("x", "a.pdf");\nawait artifact.markdown("x", "hi");`,
  407. `report({ a: 1 }, "perf");`,
  408. `for (const p of ["a"]) {\n artifact.chart("perf", ${CHART});\n}`,
  409. ];
  410. for (const script of scripts) {
  411. const analyzed = analyzeWorkflowScript(script);
  412. expect(analyzed.ok).toBe(false);
  413. expect(analyzed.diagnostics.length).toBeGreaterThan(0);
  414. for (const diagnostic of analyzed.diagnostics) {
  415. expect(diagnostic.line).toBeGreaterThan(0);
  416. expect(diagnostic.column).toBeGreaterThan(0);
  417. expect(diagnostic.message.length).toBeGreaterThan(0);
  418. }
  419. }
  420. });
  421. it("withholds the graphs, like the other authoring rules", () => {
  422. const analyzed = analyzeWorkflowScript(BAD_ARTIFACT);
  423. expect(analyzed.causality).toBeUndefined();
  424. expect(analyzed.graph).toBeUndefined();
  425. // 清单本身仍然给出(它是从站点表直接读的事实,不依赖解释)——只是这一条 id 读不出来。
  426. expect(analyzed.declaredArtifacts).toEqual([]);
  427. });
  428. it("still reports artifact diagnostics alongside the other authoring families", () => {
  429. const analyzed = analyzeWorkflowScript(
  430. [
  431. `const cmd = "lean";`,
  432. `await world.run(cmd, []);`,
  433. `await artifact.file("a b", "b.pdf");`,
  434. `phase(cmd);`,
  435. ].join("\n"),
  436. );
  437. expect(analyzed.ok).toBe(false);
  438. // 一趟报全:作者一次就能看全要改什么(与 world.run / phase 同席的理由)。
  439. const codes = new Set(analyzed.diagnostics.map((d) => d.code));
  440. expect(codes.has(ARTIFACT_DECLARATION_CODE)).toBe(true);
  441. expect(codes.size).toBeGreaterThan(1);
  442. });
  443. });
  444. describe("artifact facade siting", () => {
  445. it("rejects taking a reference to a facade artifact member", () => {
  446. const analyzed = analyzeWorkflowScript(`const publish = artifact.file;\nlog("x");`);
  447. expect(analyzed.ok).toBe(false);
  448. expect(analyzed.diagnostics[0]?.code).toBe(FACADE_SITING_CODE);
  449. expect(analyzed.diagnostics[0]?.message).toContain("'file'");
  450. });
  451. it("still allows a direct call", () => {
  452. expect(analyzeWorkflowScript(`await artifact.file("book", "b.pdf");`).ok).toBe(true);
  453. });
  454. });