@forgeax/engine-pack 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +370 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/ai-recovery.unit.test.d.ts +2 -0
  5. package/dist/__tests__/ai-recovery.unit.test.d.ts.map +1 -0
  6. package/dist/__tests__/artifact-path.test.d.ts +2 -0
  7. package/dist/__tests__/artifact-path.test.d.ts.map +1 -0
  8. package/dist/__tests__/asset-evidence-error-hints.test.d.ts +2 -0
  9. package/dist/__tests__/asset-evidence-error-hints.test.d.ts.map +1 -0
  10. package/dist/__tests__/asset-evidence-lifecycle.test.d.ts +2 -0
  11. package/dist/__tests__/asset-evidence-lifecycle.test.d.ts.map +1 -0
  12. package/dist/__tests__/asset-evidence-schema.test.d.ts +2 -0
  13. package/dist/__tests__/asset-evidence-schema.test.d.ts.map +1 -0
  14. package/dist/__tests__/atlas-cli-region-mismatch.test.d.ts +2 -0
  15. package/dist/__tests__/atlas-cli-region-mismatch.test.d.ts.map +1 -0
  16. package/dist/__tests__/atlas-error-code-owner.test-d.d.ts +2 -0
  17. package/dist/__tests__/atlas-error-code-owner.test-d.d.ts.map +1 -0
  18. package/dist/__tests__/cli-asset-evidence.integration.test.d.ts +2 -0
  19. package/dist/__tests__/cli-asset-evidence.integration.test.d.ts.map +1 -0
  20. package/dist/__tests__/cli.unit.test.d.ts +2 -0
  21. package/dist/__tests__/cli.unit.test.d.ts.map +1 -0
  22. package/dist/__tests__/evidence-source-inventory.unit.test.d.ts +2 -0
  23. package/dist/__tests__/evidence-source-inventory.unit.test.d.ts.map +1 -0
  24. package/dist/__tests__/guid-collision.unit.test.d.ts +2 -0
  25. package/dist/__tests__/guid-collision.unit.test.d.ts.map +1 -0
  26. package/dist/__tests__/guid-validator-surface.unit.test.d.ts +2 -0
  27. package/dist/__tests__/guid-validator-surface.unit.test.d.ts.map +1 -0
  28. package/dist/__tests__/load-asset-config.test.d.ts +2 -0
  29. package/dist/__tests__/load-asset-config.test.d.ts.map +1 -0
  30. package/dist/__tests__/material-cook-dependencies.unit.test.d.ts +2 -0
  31. package/dist/__tests__/material-cook-dependencies.unit.test.d.ts.map +1 -0
  32. package/dist/__tests__/material-cook-receipt.unit.test.d.ts +2 -0
  33. package/dist/__tests__/material-cook-receipt.unit.test.d.ts.map +1 -0
  34. package/dist/__tests__/material-cook-schema.unit.test.d.ts +2 -0
  35. package/dist/__tests__/material-cook-schema.unit.test.d.ts.map +1 -0
  36. package/dist/__tests__/mesh-bin-consumer-surface.unit.test.d.ts +2 -0
  37. package/dist/__tests__/mesh-bin-consumer-surface.unit.test.d.ts.map +1 -0
  38. package/dist/__tests__/mesh-bin-contract.unit.test.d.ts +2 -0
  39. package/dist/__tests__/mesh-bin-contract.unit.test.d.ts.map +1 -0
  40. package/dist/__tests__/meta-schema-optional.test.d.ts +2 -0
  41. package/dist/__tests__/meta-schema-optional.test.d.ts.map +1 -0
  42. package/dist/__tests__/meta-source-overrides.unit.test.d.ts +2 -0
  43. package/dist/__tests__/meta-source-overrides.unit.test.d.ts.map +1 -0
  44. package/dist/__tests__/native-cooker-registry.test.d.ts +2 -0
  45. package/dist/__tests__/native-cooker-registry.test.d.ts.map +1 -0
  46. package/dist/__tests__/offline-evidence-artifact-verification-owner.test-d.d.ts +2 -0
  47. package/dist/__tests__/offline-evidence-artifact-verification-owner.test-d.d.ts.map +1 -0
  48. package/dist/__tests__/offline-evidence.integration.test.d.ts +2 -0
  49. package/dist/__tests__/offline-evidence.integration.test.d.ts.map +1 -0
  50. package/dist/__tests__/pack-v2-fixture-migration.test.d.ts +2 -0
  51. package/dist/__tests__/pack-v2-fixture-migration.test.d.ts.map +1 -0
  52. package/dist/__tests__/pack-v2-schema.test.d.ts +2 -0
  53. package/dist/__tests__/pack-v2-schema.test.d.ts.map +1 -0
  54. package/dist/__tests__/pack.unit.test.d.ts +2 -0
  55. package/dist/__tests__/pack.unit.test.d.ts.map +1 -0
  56. package/dist/__tests__/producer-contract-schema.unit.test.d.ts +2 -0
  57. package/dist/__tests__/producer-contract-schema.unit.test.d.ts.map +1 -0
  58. package/dist/__tests__/resolve-asset-source.test.d.ts +2 -0
  59. package/dist/__tests__/resolve-asset-source.test.d.ts.map +1 -0
  60. package/dist/__tests__/runtime-projection.unit.test.d.ts +2 -0
  61. package/dist/__tests__/runtime-projection.unit.test.d.ts.map +1 -0
  62. package/dist/__tests__/scanner-inventory.test.d.ts +2 -0
  63. package/dist/__tests__/scanner-inventory.test.d.ts.map +1 -0
  64. package/dist/__tests__/scanner-mount-cycle.test.d.ts +2 -0
  65. package/dist/__tests__/scanner-mount-cycle.test.d.ts.map +1 -0
  66. package/dist/__tests__/scriptable-pack-cli.integration.test.d.ts +2 -0
  67. package/dist/__tests__/scriptable-pack-cli.integration.test.d.ts.map +1 -0
  68. package/dist/__tests__/scriptable-pack-ddc-key.unit.test.d.ts +2 -0
  69. package/dist/__tests__/scriptable-pack-ddc-key.unit.test.d.ts.map +1 -0
  70. package/dist/__tests__/scriptable-pack.test-d.d.ts +2 -0
  71. package/dist/__tests__/scriptable-pack.test-d.d.ts.map +1 -0
  72. package/dist/__tests__/scriptable-pack.unit.test.d.ts +2 -0
  73. package/dist/__tests__/scriptable-pack.unit.test.d.ts.map +1 -0
  74. package/dist/__tests__/topology-actions.unit.test.d.ts +2 -0
  75. package/dist/__tests__/topology-actions.unit.test.d.ts.map +1 -0
  76. package/dist/__tests__/topology.unit.test.d.ts +2 -0
  77. package/dist/__tests__/topology.unit.test.d.ts.map +1 -0
  78. package/dist/artifact-path.d.ts +9 -0
  79. package/dist/artifact-path.d.ts.map +1 -0
  80. package/dist/atlas/run-atlas.d.ts +8 -0
  81. package/dist/atlas/run-atlas.d.ts.map +1 -0
  82. package/dist/atlas/shelf-pack.d.ts +55 -0
  83. package/dist/atlas/shelf-pack.d.ts.map +1 -0
  84. package/dist/bridge.d.ts +2 -0
  85. package/dist/bridge.d.ts.map +1 -0
  86. package/dist/bridge.mjs +3 -0
  87. package/dist/bridge.mjs.map +1 -0
  88. package/dist/builtin.d.ts +24 -0
  89. package/dist/builtin.d.ts.map +1 -0
  90. package/dist/cli-asset.d.ts +22 -0
  91. package/dist/cli-asset.d.ts.map +1 -0
  92. package/dist/cli-asset.mjs +9950 -0
  93. package/dist/cli-asset.mjs.map +1 -0
  94. package/dist/config.d.ts +6 -0
  95. package/dist/config.d.ts.map +1 -0
  96. package/dist/config.mjs +29 -0
  97. package/dist/config.mjs.map +1 -0
  98. package/dist/deriveAssetName.d.ts +15 -0
  99. package/dist/deriveAssetName.d.ts.map +1 -0
  100. package/dist/errors.d.ts +30 -0
  101. package/dist/errors.d.ts.map +1 -0
  102. package/dist/errors.mjs +19 -0
  103. package/dist/errors.mjs.map +1 -0
  104. package/dist/evidence/material-cook.d.ts +70 -0
  105. package/dist/evidence/material-cook.d.ts.map +1 -0
  106. package/dist/evidence/offline-evidence.d.ts +25 -0
  107. package/dist/evidence/offline-evidence.d.ts.map +1 -0
  108. package/dist/evidence/source-inventory.d.ts +29 -0
  109. package/dist/evidence/source-inventory.d.ts.map +1 -0
  110. package/dist/guid.d.ts +45 -0
  111. package/dist/guid.d.ts.map +1 -0
  112. package/dist/guid.mjs +94 -0
  113. package/dist/guid.mjs.map +1 -0
  114. package/dist/index.d.ts +15 -0
  115. package/dist/index.d.ts.map +1 -0
  116. package/dist/index.mjs +8475 -0
  117. package/dist/index.mjs.map +1 -0
  118. package/dist/material/artifact-writer.d.ts +14 -0
  119. package/dist/material/artifact-writer.d.ts.map +1 -0
  120. package/dist/mesh-bin-contract.d.ts +36 -0
  121. package/dist/mesh-bin-contract.d.ts.map +1 -0
  122. package/dist/name.mjs +22 -0
  123. package/dist/name.mjs.map +1 -0
  124. package/dist/native-cooker-registry.d.ts +28 -0
  125. package/dist/native-cooker-registry.d.ts.map +1 -0
  126. package/dist/native-cooker.d.ts +3 -0
  127. package/dist/native-cooker.d.ts.map +1 -0
  128. package/dist/native-cooker.mjs +105 -0
  129. package/dist/native-cooker.mjs.map +1 -0
  130. package/dist/producer-contract.d.ts +19 -0
  131. package/dist/producer-contract.d.ts.map +1 -0
  132. package/dist/resolve-asset-source.d.ts +4 -0
  133. package/dist/resolve-asset-source.d.ts.map +1 -0
  134. package/dist/resolve-asset-source.mjs +99 -0
  135. package/dist/resolve-asset-source.mjs.map +1 -0
  136. package/dist/runtime-projection.d.ts +14 -0
  137. package/dist/runtime-projection.d.ts.map +1 -0
  138. package/dist/scanner.d.ts +80 -0
  139. package/dist/scanner.d.ts.map +1 -0
  140. package/dist/scanner.mjs +9015 -0
  141. package/dist/scanner.mjs.map +1 -0
  142. package/dist/schema-compiled.d.ts +12 -0
  143. package/dist/schema-compiled.d.ts.map +1 -0
  144. package/dist/schema.mjs +7369 -0
  145. package/dist/schema.mjs.map +1 -0
  146. package/dist/scriptable-pack-node.d.ts +67 -0
  147. package/dist/scriptable-pack-node.d.ts.map +1 -0
  148. package/dist/scriptable-pack-node.mjs +1590 -0
  149. package/dist/scriptable-pack-node.mjs.map +1 -0
  150. package/dist/scriptable-pack-worker.d.ts +2 -0
  151. package/dist/scriptable-pack-worker.d.ts.map +1 -0
  152. package/dist/scriptable-pack-worker.mjs +223 -0
  153. package/dist/scriptable-pack-worker.mjs.map +1 -0
  154. package/dist/scriptable-pack.d.ts +525 -0
  155. package/dist/scriptable-pack.d.ts.map +1 -0
  156. package/dist/scriptable-pack.mjs +583 -0
  157. package/dist/scriptable-pack.mjs.map +1 -0
  158. package/dist/topology.d.ts +10 -0
  159. package/dist/topology.d.ts.map +1 -0
  160. package/package.json +129 -0
  161. package/schema/meta.schema.json +173 -0
  162. package/schema/pack.schema.json +232 -0
  163. package/src/__tests__/ai-recovery.unit.test.ts +114 -0
  164. package/src/__tests__/artifact-path.test.ts +41 -0
  165. package/src/__tests__/asset-evidence-error-hints.test.ts +46 -0
  166. package/src/__tests__/asset-evidence-lifecycle.test.ts +104 -0
  167. package/src/__tests__/asset-evidence-schema.test.ts +86 -0
  168. package/src/__tests__/atlas-cli-region-mismatch.test.ts +134 -0
  169. package/src/__tests__/atlas-error-code-owner.test-d.ts +23 -0
  170. package/src/__tests__/cli-asset-evidence.integration.test.ts +172 -0
  171. package/src/__tests__/cli.unit.test.ts +448 -0
  172. package/src/__tests__/evidence-source-inventory.unit.test.ts +37 -0
  173. package/src/__tests__/guid-collision.unit.test.ts +112 -0
  174. package/src/__tests__/guid-validator-surface.unit.test.ts +20 -0
  175. package/src/__tests__/load-asset-config.test.ts +121 -0
  176. package/src/__tests__/material-cook-dependencies.unit.test.ts +45 -0
  177. package/src/__tests__/material-cook-receipt.unit.test.ts +91 -0
  178. package/src/__tests__/material-cook-schema.unit.test.ts +98 -0
  179. package/src/__tests__/mesh-bin-consumer-surface.unit.test.ts +21 -0
  180. package/src/__tests__/mesh-bin-contract.unit.test.ts +32 -0
  181. package/src/__tests__/meta-schema-optional.test.ts +116 -0
  182. package/src/__tests__/meta-source-overrides.unit.test.ts +71 -0
  183. package/src/__tests__/native-cooker-registry.test.ts +64 -0
  184. package/src/__tests__/offline-evidence-artifact-verification-owner.test-d.ts +64 -0
  185. package/src/__tests__/offline-evidence.integration.test.ts +106 -0
  186. package/src/__tests__/pack-v2-fixture-migration.test.ts +64 -0
  187. package/src/__tests__/pack-v2-schema.test.ts +142 -0
  188. package/src/__tests__/pack.unit.test.ts +2218 -0
  189. package/src/__tests__/producer-contract-schema.unit.test.ts +92 -0
  190. package/src/__tests__/resolve-asset-source.test.ts +121 -0
  191. package/src/__tests__/runtime-projection.unit.test.ts +87 -0
  192. package/src/__tests__/scanner-inventory.test.ts +72 -0
  193. package/src/__tests__/scanner-mount-cycle.test.ts +232 -0
  194. package/src/__tests__/scriptable-pack-cli.integration.test.ts +47 -0
  195. package/src/__tests__/scriptable-pack-ddc-key.unit.test.ts +63 -0
  196. package/src/__tests__/scriptable-pack.test-d.ts +131 -0
  197. package/src/__tests__/scriptable-pack.unit.test.ts +747 -0
  198. package/src/__tests__/topology-actions.unit.test.ts +94 -0
  199. package/src/__tests__/topology.unit.test.ts +85 -0
  200. package/src/artifact-path.ts +69 -0
  201. package/src/atlas/run-atlas.ts +358 -0
  202. package/src/atlas/shelf-pack.ts +176 -0
  203. package/src/atlas/upng-ambient.d.ts +13 -0
  204. package/src/bridge.ts +2 -0
  205. package/src/builtin.ts +79 -0
  206. package/src/cli-asset.ts +590 -0
  207. package/src/config.ts +36 -0
  208. package/src/deriveAssetName.ts +42 -0
  209. package/src/errors.ts +47 -0
  210. package/src/evidence/material-cook.ts +332 -0
  211. package/src/evidence/offline-evidence.ts +90 -0
  212. package/src/evidence/source-inventory.ts +193 -0
  213. package/src/guid.ts +99 -0
  214. package/src/index.ts +104 -0
  215. package/src/material/artifact-writer.ts +26 -0
  216. package/src/mesh-bin-contract.ts +150 -0
  217. package/src/native-cooker-registry.ts +163 -0
  218. package/src/native-cooker.ts +2 -0
  219. package/src/producer-contract.ts +277 -0
  220. package/src/resolve-asset-source.ts +93 -0
  221. package/src/runtime-projection.ts +100 -0
  222. package/src/scanner.ts +716 -0
  223. package/src/schema/material-cook.schema.json +79 -0
  224. package/src/schema-compiled.ts +238 -0
  225. package/src/scriptable-pack-node.ts +1390 -0
  226. package/src/scriptable-pack-worker.ts +306 -0
  227. package/src/scriptable-pack.ts +884 -0
  228. package/src/topology.ts +156 -0
@@ -0,0 +1,134 @@
1
+ // `forgeax-engine-remote-asset atlas` region-mismatch safety-net test
2
+ // (feat-20260521-sprite-atlas-animation M5' T-29 / requirements AC-10 (c)).
3
+ //
4
+ // The shelfPack pure function never produces regions whose summed area
5
+ // exceeds the atlas footprint -- that would be a packer regression. We
6
+ // still keep an `atlas-region-mismatch` invariant in runAtlas so a future
7
+ // algorithm swap (D-4 MaxRects / rectpack2D) cannot silently drop
8
+ // pixels. To exercise that branch we replace shelfPack with a vi.mock
9
+ // factory that fabricates an over-large region map; runAtlas must then
10
+ // project the failure to ImageError code='atlas-region-mismatch' with
11
+ // detail.{name, regionsTotalPixels, atlasPixels}.
12
+
13
+ import { mkdtemp, rm, writeFile } from 'node:fs/promises';
14
+ import { tmpdir } from 'node:os';
15
+ import { join } from 'node:path';
16
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
17
+
18
+ vi.mock('../atlas/shelf-pack.js', async () => {
19
+ return {
20
+ shelfPack: () => ({
21
+ ok: true,
22
+ value: {
23
+ atlasWidth: 64,
24
+ atlasHeight: 64,
25
+ regions: [
26
+ { name: 'walk-0', x: 0, y: 0, w: 64, h: 64 },
27
+ { name: 'walk-1', x: 0, y: 0, w: 64, h: 64 },
28
+ { name: 'walk-2', x: 0, y: 0, w: 64, h: 64 },
29
+ ],
30
+ },
31
+ }),
32
+ };
33
+ });
34
+
35
+ import { runCliAsset } from '../cli-asset.js';
36
+
37
+ interface CapturedIO {
38
+ stdout: string[];
39
+ stderr: string[];
40
+ }
41
+
42
+ function makeIO(): CapturedIO {
43
+ return { stdout: [], stderr: [] };
44
+ }
45
+
46
+ function ctxFor(io: CapturedIO) {
47
+ return {
48
+ stdoutWrite: (line: string): void => {
49
+ io.stdout.push(line);
50
+ },
51
+ stderrWrite: (line: string): void => {
52
+ io.stderr.push(line);
53
+ },
54
+ };
55
+ }
56
+
57
+ interface UpngEncode {
58
+ encode: (imgs: ArrayBuffer[], w: number, h: number, cnum: number) => ArrayBuffer;
59
+ }
60
+
61
+ async function loadUpng(): Promise<UpngEncode> {
62
+ const mod = (await import('upng-js')) as { default?: UpngEncode } & UpngEncode;
63
+ return (mod.default ?? mod) as UpngEncode;
64
+ }
65
+
66
+ async function writeSolidPng(
67
+ path: string,
68
+ width: number,
69
+ height: number,
70
+ rgba: [number, number, number, number],
71
+ ): Promise<void> {
72
+ const upng = await loadUpng();
73
+ const pixels = new Uint8Array(width * height * 4);
74
+ for (let i = 0; i < width * height; i++) {
75
+ pixels[i * 4 + 0] = rgba[0];
76
+ pixels[i * 4 + 1] = rgba[1];
77
+ pixels[i * 4 + 2] = rgba[2];
78
+ pixels[i * 4 + 3] = rgba[3];
79
+ }
80
+ const buf = upng.encode([pixels.buffer as ArrayBuffer], width, height, 0);
81
+ await writeFile(path, Buffer.from(buf));
82
+ }
83
+
84
+ describe('atlas CLI region-mismatch safety net (T-29 / AC-10 c)', () => {
85
+ let tmp: string;
86
+
87
+ beforeEach(async () => {
88
+ tmp = await mkdtemp(join(tmpdir(), 'atlas-cli-region-'));
89
+ });
90
+
91
+ afterEach(async () => {
92
+ await rm(tmp, { recursive: true, force: true });
93
+ });
94
+
95
+ it('exits 1 with atlas-region-mismatch + detail name/regionsTotalPixels/atlasPixels', async () => {
96
+ await writeSolidPng(join(tmp, 'walk-0.png'), 32, 32, [255, 0, 0, 255]);
97
+ await writeSolidPng(join(tmp, 'walk-1.png'), 32, 32, [0, 255, 0, 255]);
98
+ await writeSolidPng(join(tmp, 'walk-2.png'), 32, 32, [0, 0, 255, 255]);
99
+
100
+ const io = makeIO();
101
+ const code = await runCliAsset(
102
+ [
103
+ 'atlas',
104
+ '--input',
105
+ `${tmp}/*.png`,
106
+ '--name',
107
+ 'walk',
108
+ '--output',
109
+ tmp,
110
+ '--max-atlas-size',
111
+ '4096',
112
+ ],
113
+ ctxFor(io),
114
+ );
115
+
116
+ expect(code).toBe(1);
117
+ expect(io.stderr.length).toBe(1);
118
+ const parsed = JSON.parse(io.stderr[0] as string) as {
119
+ code: string;
120
+ expected: string;
121
+ hint: string;
122
+ detail?: { name?: string; regionsTotalPixels?: number; atlasPixels?: number };
123
+ };
124
+ expect(parsed.code).toBe('atlas-region-mismatch');
125
+ expect(typeof parsed.expected).toBe('string');
126
+ expect(parsed.expected.length).toBeGreaterThan(0);
127
+ expect(typeof parsed.hint).toBe('string');
128
+ expect(parsed.hint.length).toBeGreaterThan(0);
129
+ expect(typeof parsed.detail?.name).toBe('string');
130
+ expect(typeof parsed.detail?.regionsTotalPixels).toBe('number');
131
+ expect(typeof parsed.detail?.atlasPixels).toBe('number');
132
+ expect(parsed.detail?.regionsTotalPixels ?? 0).toBeGreaterThan(parsed.detail?.atlasPixels ?? 0);
133
+ });
134
+ });
@@ -0,0 +1,23 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import type { IMAGE_ERROR_HINTS } from '@forgeax/engine-types';
3
+ import { describe, expect, expectTypeOf, it } from 'vitest';
4
+
5
+ type AtlasErrorCode = Extract<keyof typeof IMAGE_ERROR_HINTS, `atlas-${string}`>;
6
+
7
+ const ownerSource = readFileSync(new URL('../atlas/run-atlas.ts', import.meta.url), 'utf8');
8
+
9
+ describe('runAtlas ErrorEnvelope.code owner', () => {
10
+ it('retains the exact public atlas code membership', () => {
11
+ expectTypeOf<AtlasErrorCode>().toEqualTypeOf<
12
+ 'atlas-empty-input' | 'atlas-size-exceeded' | 'atlas-region-mismatch'
13
+ >();
14
+ expectTypeOf<'atlas-unknown'>().not.toExtend<AtlasErrorCode>();
15
+ });
16
+
17
+ it('derives ErrorEnvelope.code from ATLAS_EXPECTED', () => {
18
+ expect(ownerSource).toContain('readonly code: keyof typeof ATLAS_EXPECTED;');
19
+ expect(ownerSource).not.toContain(
20
+ "readonly code: 'atlas-empty-input' | 'atlas-size-exceeded' | 'atlas-region-mismatch';",
21
+ );
22
+ });
23
+ });
@@ -0,0 +1,172 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { afterEach, describe, expect, it } from 'vitest';
6
+ import { runCliAsset } from '../cli-asset.js';
7
+
8
+ const guid = '11111111-1111-4111-8111-111111111111';
9
+ const tempRoots: string[] = [];
10
+
11
+ async function evidenceFixture(): Promise<string> {
12
+ const root = await mkdtemp(join(tmpdir(), 'forgeax-asset-evidence-'));
13
+ tempRoots.push(root);
14
+ await mkdir(join(root, 'assets', 'artifacts'), { recursive: true });
15
+ const bytes = Buffer.from('data');
16
+ const digest = createHash('sha256').update(bytes).digest('base64');
17
+ await writeFile(join(root, 'assets', 'artifacts', 'data.bin'), bytes);
18
+ await writeFile(
19
+ join(root, 'assets', 'config.pack.json'),
20
+ JSON.stringify({
21
+ schemaVersion: '2.0.0',
22
+ kind: 'internal-text-package',
23
+ assets: [
24
+ {
25
+ guid,
26
+ kind: 'config',
27
+ payload: { answer: 42 },
28
+ refs: [],
29
+ artifacts: {
30
+ data: {
31
+ path: 'artifacts/data.bin',
32
+ mediaType: 'application/octet-stream',
33
+ byteLength: bytes.byteLength,
34
+ integrity: { algorithm: 'sha256', digest },
35
+ },
36
+ },
37
+ },
38
+ ],
39
+ }),
40
+ );
41
+ await writeFile(join(root, 'config.source'), 'source declaration');
42
+ const meta = {
43
+ schemaVersion: '1.0.0',
44
+ kind: 'external-asset-package',
45
+ importer: 'image',
46
+ source: 'config.source',
47
+ importSettings: {},
48
+ subAssets: [{ guid, sourceIndex: 0, kind: 'config' }],
49
+ };
50
+ const metaRaw = JSON.stringify(meta);
51
+ const inputFingerprint = createHash('sha256').update(metaRaw).digest('base64');
52
+ await writeFile(join(root, 'config.source.meta.json'), metaRaw);
53
+ await writeFile(
54
+ join(root, 'receipts.json'),
55
+ JSON.stringify({
56
+ guid,
57
+ origin: 'sourceMeta',
58
+ status: 'succeeded',
59
+ inputFingerprint,
60
+ outputDigest: digest,
61
+ }),
62
+ );
63
+ await writeFile(
64
+ join(root, 'catalog.json'),
65
+ JSON.stringify([
66
+ {
67
+ guid,
68
+ packageUrl: '/assets/config.pack.json',
69
+ cookReceiptUrl: '/receipts.json',
70
+ kind: 'config',
71
+ sourcePath: 'config.source.meta.json',
72
+ },
73
+ ]),
74
+ );
75
+ return root;
76
+ }
77
+
78
+ afterEach(async () => {
79
+ for (const root of tempRoots.splice(0)) {
80
+ await import('node:fs/promises').then(({ rm }) => rm(root, { recursive: true, force: true }));
81
+ }
82
+ });
83
+
84
+ describe('asset evidence CLI contract', () => {
85
+ it('advertises the complete AI inspection and recovery vocabulary', async () => {
86
+ const stdout: string[] = [];
87
+ const stderr: string[] = [];
88
+ const code = await runCliAsset(['--help'], {
89
+ stdoutWrite: (line) => stdout.push(line),
90
+ stderrWrite: (line) => stderr.push(line),
91
+ });
92
+
93
+ expect(code).toBe(0);
94
+ expect(stderr).toEqual([]);
95
+ const help = stdout.join('\n');
96
+ for (const operation of [
97
+ 'inspect',
98
+ 'rebuild',
99
+ 'cold-cook',
100
+ 'preview-LKG',
101
+ 'override',
102
+ 'promote',
103
+ 'stop-publish',
104
+ ]) {
105
+ expect(help).toContain(operation);
106
+ }
107
+ });
108
+
109
+ it('returns the shared evidence JSON for lookup --guid --json', async () => {
110
+ const project = await evidenceFixture();
111
+ const stdout: string[] = [];
112
+ const stderr: string[] = [];
113
+ const code = await runCliAsset(
114
+ [
115
+ 'lookup',
116
+ '--guid',
117
+ guid,
118
+ '--project',
119
+ project,
120
+ '--catalog',
121
+ join(project, 'catalog.json'),
122
+ '--json',
123
+ ],
124
+ { stdoutWrite: (line) => stdout.push(line), stderrWrite: (line) => stderr.push(line) },
125
+ );
126
+
127
+ expect(code).toBe(0);
128
+ expect(stderr).toEqual([]);
129
+ const evidence = JSON.parse(stdout[0] as string) as {
130
+ guid: string;
131
+ packageUrl?: string;
132
+ cook: { status: string; freshness: string };
133
+ artifacts: Record<string, { verification: string }>;
134
+ };
135
+ expect(evidence.guid).toBe(guid);
136
+ expect(evidence.packageUrl).toBe('/assets/config.pack.json');
137
+ expect(evidence.cook.status).toBe('ready');
138
+ expect(evidence.cook.freshness).toBe('current');
139
+ const dataArtifact = evidence.artifacts.data;
140
+ expect(dataArtifact).toBeDefined();
141
+ if (dataArtifact === undefined) return;
142
+ expect(dataArtifact.verification).toBe('passed');
143
+ });
144
+
145
+ it('emits exactly one structured JSON error and no free-text protocol', async () => {
146
+ const stdout: string[] = [];
147
+ const stderr: string[] = [];
148
+ const code = await runCliAsset(
149
+ [
150
+ 'verify',
151
+ '--guid',
152
+ 'not-a-guid',
153
+ '--project',
154
+ '/project',
155
+ '--catalog',
156
+ '/project/catalog.json',
157
+ '--json',
158
+ ],
159
+ { stdoutWrite: (line) => stdout.push(line), stderrWrite: (line) => stderr.push(line) },
160
+ );
161
+
162
+ expect(code).toBe(1);
163
+ expect(stdout).toEqual([]);
164
+ expect(stderr).toHaveLength(1);
165
+ expect(JSON.parse(stderr[0] as string)).toMatchObject({
166
+ code: 'pack-guid-malformed',
167
+ expected: expect.any(String),
168
+ hint: expect.any(String),
169
+ detail: expect.any(Object),
170
+ });
171
+ });
172
+ });