|
| 1 | +// The 1.0 migration promised `meta upgrade --apply` would strip the `@forge*` attributes. |
| 2 | +// It did nothing: no entry existed in RETIRED_VOCABULARY, so the command reported |
| 3 | +// "nothing to rewrite (1 file(s) checked)", exit 0, over a project carrying nine such |
| 4 | +// nodes. A migration instruction that silently does nothing is worse than one that |
| 5 | +// refuses — the adopter believes the migration finished. |
| 6 | +// |
| 7 | +// The fix is NOT an automated strip. That vocabulary still loads for a project that opts |
| 8 | +// the provider back in (the chartered ADR-0023 path), so a rewrite would destroy valid |
| 9 | +// metadata for exactly the adopters who chose it deliberately. So the entries carry no |
| 10 | +// `rewrite`, which is the map's existing way of saying the fix is judgment: the command |
| 11 | +// names every occurrence, prints the reason and both options, and exits non-zero. |
| 12 | + |
| 13 | +import { describe, test, expect, afterAll } from "bun:test"; |
| 14 | +import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises"; |
| 15 | +import { tmpdir } from "node:os"; |
| 16 | +import { join } from "node:path"; |
| 17 | +import { run } from "../src/index.js"; |
| 18 | + |
| 19 | +const dirs: string[] = []; |
| 20 | +afterAll(async () => { for (const d of dirs) await rm(d, { recursive: true, force: true }); }); |
| 21 | + |
| 22 | +const META = { |
| 23 | + "metadata.root": { |
| 24 | + package: "acme", |
| 25 | + children: [{ |
| 26 | + "object.entity": { |
| 27 | + name: "Order", "@forgeConfidence": "high", "@forgeSource": "an interview", |
| 28 | + children: [ |
| 29 | + { "source.rdb": { "@table": "orders" } }, |
| 30 | + { "field.long": { name: "id", "@forgeRationale": "surrogate" } }, |
| 31 | + { "identity.primary": { "@fields": ["id"], "@generation": "increment" } }, |
| 32 | + ], |
| 33 | + }, |
| 34 | + }], |
| 35 | + }, |
| 36 | +}; |
| 37 | + |
| 38 | +async function upgrade(args: string[]): Promise<{ exit: number; err: string }> { |
| 39 | + const dir = await mkdtemp(join(tmpdir(), "forge-retire-")); |
| 40 | + dirs.push(dir); |
| 41 | + await mkdir(join(dir, "metaobjects"), { recursive: true }); |
| 42 | + await writeFile(join(dir, "metaobjects", "meta.json"), JSON.stringify(META), "utf8"); |
| 43 | + const lines: string[] = []; |
| 44 | + const oe = console.error, ol = console.log; |
| 45 | + console.error = (...a: unknown[]) => { lines.push(a.map(String).join(" ")); }; |
| 46 | + console.log = (...a: unknown[]) => { lines.push(a.map(String).join(" ")); }; |
| 47 | + try { return { exit: await run(["upgrade", "--cwd", dir, ...args]), err: lines.join("\n") }; } |
| 48 | + finally { console.error = oe; console.log = ol; } |
| 49 | +} |
| 50 | + |
| 51 | +describe("meta upgrade and the deregistered @forge* vocabulary", () => { |
| 52 | + test("names every occurrence and exits non-zero — not 'nothing to rewrite'", async () => { |
| 53 | + const { exit, err } = await upgrade([]); |
| 54 | + expect(exit).toBe(1); |
| 55 | + for (const attr of ["@forgeConfidence", "@forgeSource", "@forgeRationale"]) { |
| 56 | + expect(err).toContain(attr); |
| 57 | + } |
| 58 | + expect(err).not.toContain("nothing to rewrite (1 file(s) checked)"); |
| 59 | + }); |
| 60 | + |
| 61 | + test("--apply does not rewrite them — the strip would destroy valid metadata", async () => { |
| 62 | + const { exit, err } = await upgrade(["--apply"]); |
| 63 | + expect(exit).toBe(1); |
| 64 | + expect(err).toContain("needs a decision"); |
| 65 | + }); |
| 66 | + |
| 67 | + test("the message carries the reason AND both options, not just a guide link", async () => { |
| 68 | + // It used to print `Retired in <since>. See <guide>`, dropping `why` whenever a guide |
| 69 | + // existed — which is almost always — and dropping `replacedBy` unconditionally. For |
| 70 | + // this entry that removed the only actionable sentence there is. |
| 71 | + const { err } = await upgrade([]); |
| 72 | + expect(err).toContain("expected-registry.json"); // the why |
| 73 | + expect(err).toContain("forgeTypesProvider"); // keep them |
| 74 | + expect(err).toContain("or delete them"); // or don't |
| 75 | + expect(err).toContain("0.x-to-1.0.md"); // the guide |
| 76 | + // And it does not announce the retirement of something that still works elsewhere. |
| 77 | + expect(err).toContain("no longer accepted as of"); |
| 78 | + }); |
| 79 | + |
| 80 | + test("the retirement is scoped to EVERY type, because it was a common attr", async () => { |
| 81 | + // `@forgeConfidence` sits on an object here and `@forgeRationale` on a field. A |
| 82 | + // per-type entry list would cover whichever types someone thought of; the type |
| 83 | + // wildcard is what makes the row match the way the registration did. |
| 84 | + const { err } = await upgrade([]); |
| 85 | + expect(err).toContain("@forgeConfidence"); // on object.entity |
| 86 | + expect(err).toContain("@forgeRationale"); // on field.long |
| 87 | + }); |
| 88 | +}); |
0 commit comments