@fish-under-sea/dsh-agent-teams-fish 1.0.2 → 2.0.0

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 (179) hide show
  1. package/NOTICE.md +13 -7
  2. package/README.en.md +20 -12
  3. package/README.md +20 -12
  4. package/compatibility.json +82 -46
  5. package/icon.png +0 -0
  6. package/lib/artifacts.js +148 -25
  7. package/lib/client/ActivityPanel.js +26 -5
  8. package/lib/client/WorkspaceActivity.js +6 -4
  9. package/lib/client/activity-monitor.js +113 -41
  10. package/lib/client/locales.js +14 -0
  11. package/lib/client.js +433 -199
  12. package/lib/client.js.map +1 -1
  13. package/lib/command.js +7 -4
  14. package/lib/git-artifact-stamp.json +2 -2
  15. package/lib/harness-compat.js +120 -62
  16. package/lib/index.js +7 -10
  17. package/lib/mailbox.js +15 -5
  18. package/lib/members.js +221 -154
  19. package/lib/snapshot.js +15 -10
  20. package/lib/state.js +41 -8
  21. package/lib/tools.js +123 -64
  22. package/lib/types/artifacts.d.ts +6 -3
  23. package/lib/types/client/activity-monitor.d.ts +13 -4
  24. package/lib/types/client/locales.d.ts +14 -0
  25. package/lib/types/harness-compat.d.ts +63 -16
  26. package/lib/types/mailbox.d.ts +2 -0
  27. package/lib/types/members.d.ts +5 -17
  28. package/lib/types/snapshot.d.ts +12 -7
  29. package/lib/types/state.d.ts +10 -3
  30. package/lib/types/types.d.ts +5 -0
  31. package/lib/types/web-routes.d.ts +2 -0
  32. package/lib/types/workspace-audit-service.d.ts +35 -0
  33. package/lib/types/workspace-audit-worker.d.ts +1 -0
  34. package/lib/web-routes.js +31 -0
  35. package/lib/workspace-audit-service.js +165 -0
  36. package/lib/workspace-audit-worker.js +11 -0
  37. package/lib/workspace-audit.js +6 -5
  38. package/locale/en.json +6 -0
  39. package/locale/zh.json +6 -0
  40. package/package.json +69 -64
  41. package/pnpm-workspace.yaml +306 -273
  42. package/release-notes/v0.1.25.md +16 -0
  43. package/release-notes/v0.1.26.md +19 -0
  44. package/release-notes/v0.1.27.md +42 -0
  45. package/release-notes/v0.1.28.md +45 -0
  46. package/release-notes/v0.1.29.md +23 -0
  47. package/release-notes/v1.1.0.md +42 -0
  48. package/release-notes/v2.0.0.md +17 -0
  49. package/scripts/artwork-role-match.test.mjs +517 -0
  50. package/scripts/capabilities.test.mjs +301 -0
  51. package/scripts/check-install-channel.mjs +55 -0
  52. package/scripts/check-install-channel.test.mjs +39 -0
  53. package/scripts/clean-build.mjs +14 -0
  54. package/scripts/client-harness-migration.test.mjs +46 -0
  55. package/scripts/compatibility.mjs +20 -0
  56. package/scripts/compatibility.test.mjs +187 -0
  57. package/scripts/corrupt-teamjson.test.mjs +180 -0
  58. package/scripts/custom-artwork.test.mjs +273 -0
  59. package/scripts/fallback-tdd.mjs +61 -0
  60. package/scripts/fixtures/harness-benchmark-scope.mjs +16 -0
  61. package/scripts/fixtures/harness-benchmark-scope.test.mjs +18 -0
  62. package/scripts/fixtures/harness-complex-case.mjs +201 -0
  63. package/scripts/fixtures/harness-complex-case.test.mjs +21 -0
  64. package/scripts/fixtures/harness-complex-oracle.mjs +63 -0
  65. package/scripts/fixtures/harness-issue-case.mjs +51 -0
  66. package/scripts/fixtures/harness-issue159-case.mjs +28 -0
  67. package/scripts/fixtures/harness-model-case.mjs +127 -0
  68. package/scripts/fixtures/harness-model-case.test.mjs +37 -0
  69. package/scripts/fixtures/harness-model-driver.mjs +100 -0
  70. package/scripts/fixtures/harness-runtime-credentials.mjs +23 -0
  71. package/scripts/fixtures/harness-runtime-entry.mjs +171 -0
  72. package/scripts/fixtures/harness-runtime-idle.mjs +42 -0
  73. package/scripts/fixtures/harness-runtime-llm.mjs +193 -0
  74. package/scripts/fixtures/harness-runtime-protocol.mjs +187 -0
  75. package/scripts/fixtures/harness-runtime-resume.mjs +24 -0
  76. package/scripts/fixtures/harness-runtime-stability.mjs +282 -0
  77. package/scripts/fixtures/harness-runtime-tools.mjs +13 -0
  78. package/scripts/fixtures/harness-runtime-web-approval.mjs +341 -0
  79. package/scripts/fixtures/issue-336-audit-worker.mjs +18 -0
  80. package/scripts/git-artifacts.mjs +64 -0
  81. package/scripts/git-artifacts.test.mjs +32 -0
  82. package/scripts/harness-compat-tdd.mjs +492 -0
  83. package/scripts/harness-issue-verify.mjs +26 -0
  84. package/scripts/harness-model-benchmark.mjs +163 -0
  85. package/scripts/harness-runtime-platform.test.mjs +31 -0
  86. package/scripts/harness-runtime-scenarios.mjs +297 -0
  87. package/scripts/harness-runtime-verify.mjs +169 -0
  88. package/scripts/harness-source-verify.mjs +211 -0
  89. package/scripts/harness-source-verify.test.mjs +97 -0
  90. package/scripts/harness-validation.mjs +68 -0
  91. package/scripts/harness-validation.test.mjs +95 -0
  92. package/scripts/http-body.test.mjs +72 -0
  93. package/scripts/import-vendor-artwork.mjs +78 -0
  94. package/scripts/inline-plan-blank-optional-tdd.mjs +121 -0
  95. package/scripts/issue-159.test.mjs +78 -0
  96. package/scripts/issue-188.test.mjs +148 -0
  97. package/scripts/issue-189.test.mjs +100 -0
  98. package/scripts/issue-203-card.test.mjs +181 -0
  99. package/scripts/issue-205.test.mjs +163 -0
  100. package/scripts/issue-234.test.mjs +424 -0
  101. package/scripts/issue-236-stale-module.test.mjs +63 -0
  102. package/scripts/issue-236.test.mjs +59 -0
  103. package/scripts/issue-262.test.mjs +98 -0
  104. package/scripts/issue-336.test.mjs +404 -0
  105. package/scripts/legacy-session-source-repair.test.mjs +201 -0
  106. package/scripts/lifecycle-verify.mjs +1573 -0
  107. package/scripts/lineage-identity.test.mjs +77 -0
  108. package/scripts/member-failure-tdd.mjs +451 -0
  109. package/scripts/member-spawn-recovery.test.mjs +92 -0
  110. package/scripts/quality-gates-amend.test.mjs +161 -0
  111. package/scripts/quality-gates-content-bound.test.mjs +572 -0
  112. package/scripts/quality-gates-cross-binding.test.mjs +184 -0
  113. package/scripts/quality-gates-excluded-scope.test.mjs +163 -0
  114. package/scripts/quality-gates-repair-scope.test.mjs +143 -0
  115. package/scripts/quality-gates-repair-wiring.test.mjs +189 -0
  116. package/scripts/quality-gates-tdd.mjs +1238 -0
  117. package/scripts/quality-gates-work-order.test.mjs +494 -0
  118. package/scripts/readme-version.mjs +89 -0
  119. package/scripts/readme-version.test.mjs +77 -0
  120. package/scripts/release-metadata.mjs +45 -0
  121. package/scripts/release-metadata.test.mjs +66 -0
  122. package/scripts/scoped-release.test.mjs +52 -0
  123. package/scripts/stability-tdd.mjs +144 -0
  124. package/scripts/stress-verify.mjs +548 -0
  125. package/scripts/symlink-support.mjs +46 -0
  126. package/scripts/sync-skill.mjs +103 -0
  127. package/scripts/tool-policies.test.mjs +280 -0
  128. package/scripts/update-skills.mjs +105 -0
  129. package/scripts/update-skills.test.mjs +79 -0
  130. package/scripts/upgrade-status.mjs +66 -0
  131. package/scripts/upgrade-status.test.mjs +83 -0
  132. package/scripts/verify-package.mjs +73 -0
  133. package/scripts/verify.mjs +2199 -0
  134. package/scripts/web-routes-verify.mjs +142 -0
  135. package/scripts/workspace-activity.test.mjs +346 -0
  136. package/scripts/workspace-summary.test.mjs +49 -0
  137. package/src/artifacts.ts +487 -0
  138. package/src/artwork-source.ts +262 -0
  139. package/src/capabilities.ts +113 -0
  140. package/src/client/ActivityPanel.module.css +2390 -0
  141. package/src/client/ActivityPanel.tsx +1507 -0
  142. package/src/client/AgentTeamsCard.module.css +148 -0
  143. package/src/client/AgentTeamsCard.tsx +155 -0
  144. package/src/client/StagingPlanEditor.tsx +829 -0
  145. package/src/client/TeamChatEntry.tsx +27 -0
  146. package/src/client/WorkspaceActivity.module.css +41 -0
  147. package/src/client/WorkspaceActivity.tsx +137 -0
  148. package/src/client/activity-model.ts +372 -0
  149. package/src/client/activity-monitor.ts +440 -0
  150. package/src/client/agent-teams-card-definition.ts +250 -0
  151. package/src/client/artwork.ts +374 -0
  152. package/src/client/icons.tsx +17 -0
  153. package/src/client/index.tsx +140 -0
  154. package/src/client/locales.ts +481 -0
  155. package/src/client/panel-geometry.ts +194 -0
  156. package/src/client/session-navigation.ts +73 -0
  157. package/src/client/workspace-state.ts +52 -0
  158. package/src/command.ts +145 -0
  159. package/src/css-modules.d.ts +4 -0
  160. package/src/event-types.ts +177 -0
  161. package/src/events.ts +78 -0
  162. package/src/harness-compat.ts +570 -0
  163. package/src/index.ts +599 -0
  164. package/src/lineage.ts +248 -0
  165. package/src/mailbox.ts +185 -0
  166. package/src/members.ts +1230 -0
  167. package/src/profiles.ts +765 -0
  168. package/src/quality-gates.ts +2124 -0
  169. package/src/scheduler.ts +554 -0
  170. package/src/snapshot.ts +333 -0
  171. package/src/state.ts +1317 -0
  172. package/src/tool-names.ts +14 -0
  173. package/src/tool-policies.ts +219 -0
  174. package/src/tools.ts +2939 -0
  175. package/src/types.ts +414 -0
  176. package/src/web-routes.ts +128 -0
  177. package/src/workspace-audit-service.ts +182 -0
  178. package/src/workspace-audit-worker.ts +12 -0
  179. package/src/workspace-audit.ts +57 -0
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env node
2
+ /** Real published Harness product-entry verification. Only the model is a fixture.
3
+ * Usage: node scripts/harness-runtime-verify.mjs --host-version <exact>
4
+ * --artifact <package.tgz> --report-dir <isolated-directory>
5
+ * Optional: --runtime-dir <already prepared directory> --prepare-only
6
+ */
7
+ import { runRuntimeScenarios, runtimeScenarios, runPluginInstallation } from './harness-runtime-scenarios.mjs';
8
+ import { spawn } from 'node:child_process';
9
+ import { mkdirSync, writeFileSync, readFileSync, existsSync, copyFileSync } from 'node:fs';
10
+ import { resolve, join, dirname } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { createHash } from 'node:crypto';
13
+ const allowedFlags = new Set(['--host-version', '--artifact', '--report-dir', '--runtime-dir', '--scenario', '--prepare-only']);
14
+ const flags = new Map();
15
+ for (let i = 2; i < process.argv.length; i++) {
16
+ const arg = process.argv[i];
17
+ if (!allowedFlags.has(arg) || flags.has(arg)) throw Error('Unknown or duplicate argument ' + arg);
18
+ if (arg === '--prepare-only')
19
+ flags.set(arg, true);
20
+ else if (arg.startsWith('--') && process.argv[i + 1])
21
+ flags.set(arg, process.argv[++i]);
22
+ else
23
+ throw Error('Invalid argument ' + arg);
24
+ }
25
+ const scenarios = runtimeScenarios;
26
+ if (flags.has('--scenario') && !scenarios.includes(flags.get('--scenario'))) throw Error('Unknown scenario');
27
+ const version = flags.get('--host-version');
28
+ if (typeof version !== 'string' || !/^\d+\.\d+\.\d+(?:-[\w.]+)?$/.test(version))
29
+ throw Error('--host-version must be an exact version');
30
+ if (!flags.has('--report-dir'))
31
+ throw Error('--report-dir required');
32
+ const report = resolve(flags.get('--report-dir')), runtime = resolve(flags.get('--runtime-dir') ?? join(report, 'runtime'));
33
+ mkdirSync(report, { recursive: true });
34
+ mkdirSync(runtime, { recursive: true });
35
+ const registry = 'https://registry.npmjs.org';
36
+ const isDsh = name => /^@deepseek-ai\/dsh(?:-|$)/.test(name);
37
+ const json = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
38
+ const hash = path => createHash('sha256').update(readFileSync(path)).digest('hex');
39
+ const userConfig = process.platform === 'win32' ? 'NUL' : '/dev/null';
40
+ // Native install scripts (koffi's cnoke, node-pty) need the Windows shell and
41
+ // profile directories. The fixture environment is deliberately minimal, so
42
+ // forward exactly the variables those builds read instead of the whole block.
43
+ const windowsEnvironment = process.platform === 'win32'
44
+ ? Object.fromEntries(['LOCALAPPDATA', 'APPDATA', 'USERPROFILE', 'SYSTEMROOT', 'SystemRoot', 'ComSpec', 'PATHEXT', 'TEMP', 'TMP']
45
+ .map(name => [name, process.env[name]]).filter(([, value]) => value !== undefined))
46
+ : {};
47
+ // The DSH CLI installs plugins through an external pnpm. Pin the shim directory
48
+ // at the front of the fixture PATH so command lookups inside the spawned shell
49
+ // resolve the same package manager this runner already uses.
50
+ const packageManagerPath = process.platform === 'win32'
51
+ ? [join(process.env.APPDATA ?? '', 'npm')].filter(existsSync).join(';')
52
+ : dirname(process.execPath);
53
+ const fixturePath = packageManagerPath ? packageManagerPath + (process.platform === 'win32' ? ';' : ':') + process.env.PATH : process.env.PATH;
54
+ const environment = (extra = {}) => ({ PATH: fixturePath, LANG: process.env.LANG ?? 'en_US.UTF-8', HOME: join(report, 'user-home'), TMPDIR: join(report, 'tmp'), npm_config_userconfig: userConfig, npm_config_registry: registry, ...windowsEnvironment, ...extra });
55
+ mkdirSync(join(report, 'user-home'), { recursive: true });
56
+ mkdirSync(join(report, 'tmp'), { recursive: true });
57
+ /**
58
+ * Windows resolves `npm` only through its `npm.cmd` shim: CreateProcess appends
59
+ * `.exe` alone, and Node refuses to launch a batch file without a shell. Route
60
+ * the package-manager invocation through the command interpreter so the runner
61
+ * behaves the same on every host the matrix covers.
62
+ */
63
+ function spawnTarget(argv) {
64
+ if (process.platform !== 'win32' || !/^npm(?:\.cmd)?$/i.test(argv[0])) return [argv[0], argv.slice(1)];
65
+ const quote = value => /[\s&|<>^()]/.test(value) ? `"${value.replaceAll('"', '""')}"` : value;
66
+ const line = [argv[0], ...argv.slice(1)].map(quote).join(' ');
67
+ return [process.env.ComSpec ?? 'cmd.exe', ['/d', '/s', '/c', line], true];
68
+ }
69
+ async function command(argv, cwd, env, label, timeoutMs = 900000) {
70
+ const [file, args, verbatim] = spawnTarget(argv);
71
+ const child = spawn(file, args, {
72
+ cwd, env, stdio: ['ignore', 'pipe', 'pipe'],
73
+ ...verbatim === true ? { windowsVerbatimArguments: true } : {},
74
+ });
75
+ let stdout = '', stderr = '', timedOut = false;
76
+ child.stdout.on('data', x => stdout += x);
77
+ child.stderr.on('data', x => stderr += x);
78
+ const timer = setTimeout(() => { timedOut = true; child.kill('SIGTERM'); setTimeout(() => child.kill('SIGKILL'), 5000).unref(); }, timeoutMs);
79
+ const exit = await new Promise((resolve, reject) => { child.on('error', reject); child.on('exit', (code, signal) => resolve({ code, signal })); });
80
+ clearTimeout(timer);
81
+ writeFileSync(join(report, label + '.stdout.log'), stdout);
82
+ writeFileSync(join(report, label + '.stderr.log'), stderr);
83
+ return { ...exit, timedOut, stdout, stderr };
84
+ }
85
+ async function exactMetadata(name) {
86
+ const response = await fetch(registry + '/' + encodeURIComponent(name) + '/' + version, { signal: AbortSignal.timeout(60000) });
87
+ if (!response.ok)
88
+ throw Error(`Registry lacks coherent target ${name}@${version}: HTTP ${response.status}`);
89
+ const pkg = await response.json();
90
+ if (pkg.name !== name || pkg.version !== version)
91
+ throw Error('Registry identity mismatch: ' + name);
92
+ return pkg;
93
+ }
94
+ async function collectCohort() {
95
+ const packages = new Map(), pending = new Set(['@deepseek-ai/dsh']);
96
+ while (pending.size) {
97
+ const batch = [...pending].filter(x => !packages.has(x)).slice(0, 16);
98
+ if (!batch.length)
99
+ break;
100
+ for (const name of batch)
101
+ pending.delete(name);
102
+ const results = await Promise.all(batch.map(exactMetadata));
103
+ for (const pkg of results) {
104
+ packages.set(pkg.name, pkg);
105
+ for (const name of Object.keys({ ...pkg.dependencies, ...pkg.optionalDependencies, ...pkg.peerDependencies }))
106
+ if (isDsh(name) && !packages.has(name))
107
+ pending.add(name);
108
+ }
109
+ }
110
+ return packages;
111
+ }
112
+ function verifyCohort() {
113
+ const lock = JSON.parse(readFileSync(join(runtime, 'package-lock.json'), 'utf8')), cohort = [];
114
+ for (const [path, entry] of Object.entries(lock.packages)) {
115
+ if (!/node_modules\/@deepseek-ai\/dsh(?:-[^/]+)?$/.test(path))
116
+ continue;
117
+ const installed = JSON.parse(readFileSync(join(runtime, path, 'package.json'), 'utf8'));
118
+ if (entry.version !== version || installed.version !== version)
119
+ throw Error(`Mixed host cohort ${path}: lock ${entry.version}, disk ${installed.version}, expected ${version}`);
120
+ cohort.push({ path, name: installed.name, version: entry.version, integrity: entry.integrity });
121
+ }
122
+ if (!cohort.some(x => x.name === '@deepseek-ai/dsh'))
123
+ throw Error('No actual Harness installation');
124
+ const result = { version, count: cohort.length, lockSha256: hash(join(runtime, 'package-lock.json')), cohort };
125
+ json(join(report, 'cohort.json'), result);
126
+ return result;
127
+ }
128
+ const testFiles = Object.fromEntries(['compatibility.mjs', '../compatibility.json', 'harness-validation.mjs', 'harness-runtime-verify.mjs', 'harness-runtime-scenarios.mjs', 'fixtures/harness-runtime-llm.mjs', 'fixtures/harness-runtime-resume.mjs', 'fixtures/harness-runtime-idle.mjs', 'fixtures/harness-runtime-entry.mjs', 'fixtures/harness-runtime-web-approval.mjs', 'fixtures/harness-runtime-credentials.mjs', 'fixtures/harness-runtime-protocol.mjs', 'fixtures/harness-runtime-stability.mjs', 'fixtures/harness-runtime-tools.mjs'].map(path => [path, hash(join(dirname(fileURLToPath(import.meta.url)), path))]));
129
+ let artifactSha;
130
+ const manifestPath = join(runtime, 'package.json');
131
+ let manifest = existsSync(manifestPath) ? JSON.parse(readFileSync(manifestPath, 'utf8')) : undefined;
132
+ if (manifest && !['agentteams-harness-runtime-test', 'agentteams-harness-runtime-lab'].includes(manifest.name))
133
+ throw Error('Runtime directory is not owned by this test; choose a fresh --runtime-dir');
134
+ if (manifest?.dependencies?.['@deepseek-ai/dsh'] !== version) {
135
+ if (manifest)
136
+ throw Error('Runtime directory belongs to a different dependency state; use a new directory');
137
+ const cohort = await collectCohort();
138
+ json(join(report, 'registry-cohort.json'), { capturedAt: new Date().toISOString(), registry, version, packages: [...cohort.values()].map(p => ({ name: p.name, version: p.version, gitHead: p.gitHead, dist: p.dist })) });
139
+ manifest = { name: 'agentteams-harness-runtime-test', version: '0.0.0', private: true, type: 'module', dependencies: { '@deepseek-ai/dsh': version }, overrides: Object.fromEntries([...cohort.keys()].map(name => [name, version])) };
140
+ }
141
+ if (flags.has('--artifact')) {
142
+ const artifact = resolve(flags.get('--artifact'));
143
+ artifactSha = hash(artifact);
144
+ const ownArtifact = join(report, 'artifact-' + artifactSha + '.tgz');
145
+ copyFileSync(artifact, ownArtifact);
146
+ manifest.dependencies['@fish-under-sea/dsh-agent-teams-fish'] = 'file:' + ownArtifact;
147
+ }
148
+ else if (!flags.has('--prepare-only'))
149
+ throw Error('--artifact required unless --prepare-only');
150
+ json(manifestPath, manifest);
151
+ const install = await command(['npm', 'install', '--prefer-online', '--no-audit', '--no-fund', '--registry=' + registry, '--userconfig=' + userConfig], runtime, environment({ 'npm_config_cache': process.env.npm_config_cache ?? join(report, 'npm-cache') }), 'install');
152
+ if (install.code !== 0)
153
+ throw Error('npm installation failed; see ' + join(report, 'install.stderr.log'));
154
+ const cohort = verifyCohort();
155
+ if (flags.has('--prepare-only')) {
156
+ json(join(report, 'result.json'), { prepared: true, version, runtime, cohortCount: cohort.count });
157
+ console.log('Prepared ' + version + ' with ' + cohort.count + ' exact DSH packages');
158
+ process.exit(0);
159
+ }
160
+ const plugin = JSON.parse(readFileSync(join(runtime, 'node_modules/@fish-under-sea/dsh-agent-teams-fish/package.json'), 'utf8'));
161
+ if (plugin.name !== '@fish-under-sea/dsh-agent-teams-fish') throw Error('Artifact package identity does not match AgentTeams');
162
+ const runs = await runRuntimeScenarios({ report, runtime, command, environment, selectedScenarios: flags.has('--scenario') ? [flags.get('--scenario')] : scenarios });
163
+ // Exercise the same compatibility gate used by the plugin settings UI. Runtime
164
+ // fixtures alone link the package directly and cannot prove installation works.
165
+ runs.push(...await runPluginInstallation({ version, pluginVersion: plugin.version, artifact: flags.get('--artifact'), runtime, report, command, environment }));
166
+ const passed = runs.every(x => x.passed);
167
+ json(join(report, 'result.json'), { passed, version, artifactSha256: artifactSha, pluginVersion: plugin.version, testFiles, node: process.version, platform: process.platform, arch: process.arch, cohortCount: cohort.count, runs, unverified: ['real provider APIs and credentials', 'browser interaction', 'other operating systems', 'native terminal execution', 'live user-data migration'] });
168
+ console.log(JSON.stringify({ passed, version, report, runs }, null, 2));
169
+ process.exitCode = passed ? 0 : 1;
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Verify a packed plugin against an already built, exact Harness source checkout.
4
+ * No package is published, no host manifest is changed, and no profile is reused.
5
+ *
6
+ * node scripts/harness-source-verify.mjs --host-dir /path/to/deepseek-harness
7
+ * --artifact /path/to/plugin.tgz --report-dir /tmp/new-report
8
+ * [--candidate-version 0.2.0] [--scenario lifecycle] [--prepare-only]
9
+ *
10
+ * Build the host with its own build:lib:host and build:lib:client scripts first.
11
+ * Candidate versions exercise the host's real compatibility evaluator with an
12
+ * explicit runtimeVersion; scenarios still execute the recorded source version.
13
+ */
14
+ import { spawn, execFileSync } from 'node:child_process';
15
+ import { createHash } from 'node:crypto';
16
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, symlinkSync, writeFileSync } from 'node:fs';
17
+ import { createRequire } from 'node:module';
18
+ import { dirname, join, resolve } from 'node:path';
19
+ import { fileURLToPath, pathToFileURL } from 'node:url';
20
+ import { runRuntimeScenarios, runtimeScenarios } from './harness-runtime-scenarios.mjs';
21
+
22
+ const scriptDir = dirname(fileURLToPath(import.meta.url));
23
+ const pluginName = '@fish-under-sea/dsh-agent-teams-fish';
24
+ const isDsh = name => name === '@deepseek-ai/dsh' || name.startsWith('@deepseek-ai/dsh-');
25
+ const sha256 = path => createHash('sha256').update(readFileSync(path)).digest('hex');
26
+ const readJson = path => JSON.parse(readFileSync(path, 'utf8'));
27
+ const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
28
+
29
+ /** Reject registry-runner arguments and ambiguous/missing source-runner inputs. */
30
+ export function parseSourceArguments(argv) {
31
+ const allowed = new Set(['--host-dir', '--artifact', '--report-dir', '--candidate-version', '--scenario', '--prepare-only']);
32
+ const flags = new Map();
33
+ for (let index = 0; index < argv.length; index++) {
34
+ const flag = argv[index];
35
+ if (!allowed.has(flag) || flags.has(flag)) throw Error('Unknown or duplicate source argument ' + flag);
36
+ if (flag === '--prepare-only') flags.set(flag, true);
37
+ else {
38
+ const value = argv[++index];
39
+ if (!value || value.startsWith('--')) throw Error('Missing value for ' + flag);
40
+ flags.set(flag, value);
41
+ }
42
+ }
43
+ for (const required of ['--host-dir', '--artifact', '--report-dir']) {
44
+ if (!flags.has(required)) throw Error(required + ' required');
45
+ }
46
+ if (flags.has('--scenario') && !runtimeScenarios.includes(flags.get('--scenario'))) throw Error('Unknown scenario');
47
+ return flags;
48
+ }
49
+
50
+ /** Limit source discovery to tracked package manifests in the host's package tiers. */
51
+ export function discoverWorkspacePackages(host, trackedFiles) {
52
+ const packages = new Map();
53
+ for (const path of trackedFiles) {
54
+ if (!/^(?:vendor\/[^/]+|packages\/[^/]+\/[^/]+|apps\/[^/]+|native\/system(?:\/packages\/[^/]+)?)\/package\.json$/.test(path)) continue;
55
+ const manifestPath = join(host, path), manifest = readJson(manifestPath);
56
+ if (typeof manifest.name !== 'string' || typeof manifest.version !== 'string') throw Error('Invalid workspace manifest: ' + path);
57
+ if (packages.has(manifest.name)) throw Error('Duplicate workspace package: ' + manifest.name);
58
+ packages.set(manifest.name, { name: manifest.name, version: manifest.version, directory: realpathSync(dirname(manifestPath)), manifestPath, manifestSha256: sha256(manifestPath), manifest });
59
+ }
60
+ for (const required of ['@deepseek-ai/dsh', '@deepseek-ai/dsh-app-boot', '@deepseek-ai/cordis']) {
61
+ if (!packages.has(required)) throw Error('Missing source workspace package: ' + required);
62
+ }
63
+ return packages;
64
+ }
65
+
66
+ /** Reject a candidate claim for any checkout other than the exact recorded source. */
67
+ export function selectSourceCandidate(policy, candidateVersion, sourceCommit, sourceClean) {
68
+ const candidates = policy.sourceCandidates ?? [];
69
+ const candidate = candidateVersion
70
+ ? candidates.find(entry => entry.version === candidateVersion)
71
+ : candidates.find(entry => entry.commit === sourceCommit);
72
+ if (!candidate) throw Error('No matching sourceCandidates entry; specify a policy-pinned candidate version');
73
+ if (!sourceClean) throw Error('Candidate verification requires a clean tracked source checkout');
74
+ if (candidate.commit !== sourceCommit) throw Error('Source commit does not match the candidate policy: ' + candidate.commit);
75
+ return candidate;
76
+ }
77
+
78
+ function resolveManifest(name, fromDirectory) {
79
+ const require = createRequire(join(fromDirectory, 'package.json'));
80
+ // Read the installed root manifest in Node's package search order. Export
81
+ // maps can hide package.json or redirect it to a nameless dist manifest;
82
+ // neither should change the identity of the installed dependency.
83
+ for (const directory of require.resolve.paths(name) ?? []) {
84
+ const candidate = join(directory, name, 'package.json');
85
+ if (existsSync(candidate)) return realpathSync(candidate);
86
+ }
87
+ const error = Error('No installed package manifest for ' + name);
88
+ error.code = 'MODULE_NOT_FOUND';
89
+ throw error;
90
+ }
91
+
92
+ /** Inventory the resolved declared closure; reject registry DSH/vendor duplicates. */
93
+ export function inspectResolvedCohort(workspaces, roots) {
94
+ const pending = [...roots], visited = new Set(), packages = [], edges = [];
95
+ while (pending.length) {
96
+ const directory = realpathSync(pending.shift());
97
+ if (visited.has(directory)) continue;
98
+ visited.add(directory);
99
+ const manifestPath = join(directory, 'package.json'), manifest = readJson(manifestPath);
100
+ if (typeof manifest.name !== 'string' || typeof manifest.version !== 'string') throw Error('Resolved package has no identity: ' + manifestPath);
101
+ const workspace = workspaces.get(manifest.name);
102
+ if (workspace && workspace.directory !== directory) throw Error(`Mixed source closure: ${manifest.name} resolved to ${directory}, expected ${workspace.directory}`);
103
+ if (isDsh(manifest.name) && !workspace) throw Error('DSH package outside tracked source workspace: ' + manifest.name);
104
+ packages.push({ name: manifest.name, version: manifest.version, directory, manifestSha256: sha256(manifestPath), workspace: Boolean(workspace) });
105
+ const dependencies = { ...manifest.dependencies, ...manifest.peerDependencies, ...manifest.optionalDependencies };
106
+ for (const name of Object.keys(dependencies).sort()) {
107
+ const optional = Object.hasOwn(manifest.optionalDependencies ?? {}, name) || manifest.peerDependenciesMeta?.[name]?.optional === true;
108
+ let target;
109
+ try { target = resolveManifest(name, directory); }
110
+ catch (error) {
111
+ if (optional && error.code === 'MODULE_NOT_FOUND') {
112
+ edges.push({ from: manifest.name, fromDirectory: directory, name, optional: true, missing: true });
113
+ continue;
114
+ }
115
+ throw Error(`Cannot resolve ${manifest.name} dependency ${name}: ${error.message}`, { cause: error });
116
+ }
117
+ const targetDirectory = realpathSync(dirname(target));
118
+ edges.push({ from: manifest.name, fromDirectory: directory, name, optional, directory: targetDirectory });
119
+ pending.push(targetDirectory);
120
+ }
121
+ }
122
+ return { kind: 'resolved-declared-dependency-closure', count: packages.filter(pkg => isDsh(pkg.name)).length, packages, edges };
123
+ }
124
+
125
+ /** Call the unmodified host evaluator, with no version exemption. */
126
+ export function evaluateCandidateGate(evaluate, manifest, candidateVersion) {
127
+ const issue = evaluate(manifest, {}, candidateVersion);
128
+ return { kind: 'simulated-runtime-version-gate', runtimeVersion: candidateVersion, passed: issue === undefined, exemptions: {}, incompatible: issue ?? null, changesHostManifests: false, verifiesPublishedRelease: false };
129
+ }
130
+
131
+ function isolatedEnvironment(report, extra = {}) {
132
+ return { PATH: process.env.PATH, LANG: process.env.LANG ?? 'en_US.UTF-8', HOME: join(report, 'user-home'), TMPDIR: join(report, 'tmp'), npm_config_userconfig: '/dev/null', ...extra };
133
+ }
134
+
135
+ function commandRunner(report) {
136
+ return async (argv, cwd, env, label, timeoutMs = 900000) => {
137
+ const child = spawn(argv[0], argv.slice(1), { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
138
+ let stdout = '', stderr = '', timedOut = false;
139
+ child.stdout.on('data', data => { stdout += data; });
140
+ child.stderr.on('data', data => { stderr += data; });
141
+ const timer = setTimeout(() => { timedOut = true; child.kill('SIGTERM'); setTimeout(() => child.kill('SIGKILL'), 5000).unref(); }, timeoutMs);
142
+ let exit;
143
+ try { exit = await new Promise((resolveExit, reject) => { child.on('error', reject); child.on('exit', (code, signal) => resolveExit({ code, signal })); }); }
144
+ finally { clearTimeout(timer); }
145
+ writeFileSync(join(report, label + '.stdout.log'), stdout);
146
+ writeFileSync(join(report, label + '.stderr.log'), stderr);
147
+ return { ...exit, timedOut, stdout, stderr };
148
+ };
149
+ }
150
+
151
+ /** Extract only npm package files/directories through the host's installed tar library. */
152
+ async function extractArtifact(host, artifact, destination) {
153
+ const require = createRequire(join(host, 'package.json'));
154
+ const tar = require('tar');
155
+ await tar.x({ file: artifact, cwd: destination, strip: 1, strict: true, filter: (path, entry) => {
156
+ if (!path.startsWith('package/') || path.split('/').includes('..') || path.includes('\\') || !['File', 'Directory'].includes(entry.type)) throw Error('Unsupported artifact entry: ' + path);
157
+ return true;
158
+ } });
159
+ }
160
+
161
+ /** Execute source validation, leaving reports and profiles available for inspection. */
162
+ export async function verifySource(argv) {
163
+ const flags = parseSourceArguments(argv);
164
+ const host = realpathSync(resolve(flags.get('--host-dir'))), artifact = realpathSync(resolve(flags.get('--artifact'))), report = resolve(flags.get('--report-dir'));
165
+ if (existsSync(report) && readdirSync(report).length) throw Error('Report directory must be new or empty');
166
+ const git = (...args) => execFileSync('git', ['-C', host, ...args], { encoding: 'utf8' }).trim();
167
+ const sourceCommit = git('rev-parse', 'HEAD'), sourceStatus = git('status', '--porcelain', '--untracked-files=no');
168
+ const policy = readJson(join(scriptDir, '../compatibility.json'));
169
+ const candidate = selectSourceCandidate(policy, flags.get('--candidate-version'), sourceCommit, sourceStatus === '');
170
+ const packages = discoverWorkspacePackages(host, git('ls-files').split('\n'));
171
+ const cli = packages.get('@deepseek-ai/dsh'), boot = packages.get('@deepseek-ai/dsh-app-boot');
172
+ for (const path of [join(cli.directory, 'lib/bin.js'), join(boot.directory, 'lib/index.js')]) {
173
+ if (!existsSync(path)) throw Error('Build host and client libraries before verification; missing ' + path);
174
+ }
175
+ mkdirSync(report, { recursive: true });
176
+ for (const name of ['user-home', 'tmp', 'runtime/node_modules']) mkdirSync(join(report, name), { recursive: true });
177
+ const runtime = join(report, 'runtime'), modules = join(runtime, 'node_modules');
178
+ for (const pkg of packages.values()) {
179
+ const target = join(modules, pkg.name);
180
+ mkdirSync(dirname(target), { recursive: true });
181
+ symlinkSync(pkg.directory, target, 'dir');
182
+ }
183
+ const pluginDirectory = join(modules, pluginName);
184
+ mkdirSync(pluginDirectory, { recursive: true });
185
+ const artifactSha256 = sha256(artifact), retainedArtifact = join(report, 'artifact-' + artifactSha256 + '.tgz');
186
+ copyFileSync(artifact, retainedArtifact);
187
+ await extractArtifact(host, retainedArtifact, pluginDirectory);
188
+ const plugin = readJson(join(pluginDirectory, 'package.json'));
189
+ if (plugin.name !== pluginName) throw Error('Artifact package identity does not match AgentTeams');
190
+ // Resolve external host identities from this prepared namespace, never from
191
+ // the plugin checkout's development dependencies or another user profile.
192
+ symlinkSync(modules, join(pluginDirectory, 'node_modules'), 'dir');
193
+ const cohort = inspectResolvedCohort(packages, [cli.directory, pluginDirectory]);
194
+ writeJson(join(report, 'cohort.json'), cohort);
195
+ const { evaluatePluginCompatibility } = await import(pathToFileURL(join(boot.directory, 'lib/index.js')).href);
196
+ const gate = evaluateCandidateGate(evaluatePluginCompatibility, plugin, candidate.version);
197
+ writeJson(join(report, 'candidate-gate.json'), gate);
198
+ const source = { kind: 'local-source-checkout', directory: host, repository: candidate.repository, commit: sourceCommit, trackedClean: sourceStatus === '', runtimeVersion: boot.version, cliManifestVersion: cli.version, buildMode: 'prebuilt-workspace', buildFreshness: 'caller-responsibility', cliSha256: sha256(join(cli.directory, 'lib/bin.js')), appBootSha256: sha256(join(boot.directory, 'lib/index.js')), lockSha256: sha256(join(host, 'pnpm-lock.yaml')) };
199
+ const testFiles = Object.fromEntries(['harness-source-verify.mjs', 'harness-runtime-scenarios.mjs', ...readdirSync(join(scriptDir, 'fixtures')).filter(name => /^harness-runtime-.*\.mjs$/.test(name)).map(name => 'fixtures/' + name)].map(path => [path, sha256(join(scriptDir, path))]));
200
+ const command = commandRunner(report), environment = extra => isolatedEnvironment(report, extra);
201
+ const runs = flags.has('--prepare-only') || !gate.passed ? [] : await runRuntimeScenarios({ report, runtime, command, environment, selectedScenarios: flags.has('--scenario') ? [flags.get('--scenario')] : runtimeScenarios, linkWorkspacePackages: true });
202
+ const result = { kind: 'source-candidate-verification', passed: gate.passed && (flags.has('--prepare-only') || runs.every(run => run.passed)), preparedOnly: flags.has('--prepare-only'), source, candidateGate: gate, artifactSha256, pluginVersion: plugin.version, testFiles, node: process.version, platform: process.platform, arch: process.arch, cohortCount: cohort.count, workspaceInventoryCount: packages.size, runs, unverified: ['published candidate-version artifact and dependency closure', 'npm/GitHub installation', 'real provider APIs and credentials', 'browser interaction', 'packaged Electron launch', 'other operating systems', 'native terminal execution', 'live user-data migration', 'prebuilt libraries reproducibly matching source checkout'] };
203
+ writeJson(join(report, 'result.json'), result);
204
+ console.log(JSON.stringify({ kind: result.kind, passed: result.passed, sourceCommit, sourceRuntimeVersion: source.runtimeVersion, candidateVersion: candidate.version, preparedOnly: result.preparedOnly, report, runs: runs.map(run => ({ scenario: run.scenario, passed: run.passed })) }, null, 2));
205
+ return result.passed;
206
+ }
207
+
208
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
209
+ try { process.exitCode = await verifySource(process.argv.slice(2)) ? 0 : 1; }
210
+ catch (error) { console.error(error.stack ?? error); process.exitCode = 1; }
211
+ }
@@ -0,0 +1,97 @@
1
+ import assert from 'node:assert/strict';
2
+ import { mkdtempSync, mkdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { test } from 'node:test';
6
+ import { discoverWorkspacePackages, inspectResolvedCohort, parseSourceArguments, selectSourceCandidate } from './harness-source-verify.mjs';
7
+
8
+ const baseArgs = ['--host-dir', '/host', '--artifact', '/plugin.tgz', '--report-dir', '/report'];
9
+ const commit = 'a'.repeat(40);
10
+ const candidate = { version: '0.2.0', commit, repository: 'https://github.com/deepseek-ai/deepseek-harness' };
11
+
12
+ test('source invocation cannot masquerade as an npm host-version verification', () => {
13
+ assert.throws(() => parseSourceArguments([...baseArgs, '--host-version', '0.2.0']), /Unknown/);
14
+ assert.throws(() => parseSourceArguments([...baseArgs, '--runtime-dir', '/existing-profile']), /Unknown/);
15
+ assert.throws(() => parseSourceArguments(['--host-dir', '--artifact', 'file']), /Missing value/);
16
+ assert.throws(() => parseSourceArguments([...baseArgs, '--artifact', 'other']), /duplicate/);
17
+ assert.throws(() => parseSourceArguments(baseArgs.slice(0, -2)), /report-dir required/);
18
+ assert.throws(() => parseSourceArguments([...baseArgs, '--scenario', 'pretend-pass']), /Unknown scenario/);
19
+ });
20
+
21
+ test('candidate acceptance requires the policy SHA and a clean source checkout', () => {
22
+ const policy = { supportedHosts: [{ version: '0.1.7-rc.2' }], sourceCandidates: [candidate] };
23
+ assert.equal(selectSourceCandidate(policy, undefined, commit, true), candidate);
24
+ assert.equal(selectSourceCandidate(policy, '0.2.0', commit, true), candidate);
25
+ assert.throws(() => selectSourceCandidate(policy, '0.1.7-rc.2', commit, true), /No matching/);
26
+ assert.throws(() => selectSourceCandidate(policy, '0.2.0', 'b'.repeat(40), true), /does not match/);
27
+ assert.throws(() => selectSourceCandidate(policy, '0.2.0', commit, false), /clean tracked/);
28
+ assert.throws(() => selectSourceCandidate({ supportedHosts: ['0.2.0'] }, '0.2.0', commit, true), /No matching/);
29
+ });
30
+
31
+ function sandbox(t) {
32
+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'agentteams-source-verifier-test-')));
33
+ t.after(() => rmSync(root, { recursive: true, force: true }));
34
+ return root;
35
+ }
36
+
37
+ function manifest(root, path, name, extra = {}) {
38
+ const directory = join(root, path);
39
+ mkdirSync(directory, { recursive: true });
40
+ writeFileSync(join(directory, 'package.json'), JSON.stringify({ name, version: '0.1.7-rc.2', ...extra }));
41
+ return directory;
42
+ }
43
+
44
+ test('workspace discovery ignores generated residue and rejects duplicate identities', t => {
45
+ const root = sandbox(t);
46
+ const paths = ['apps/cli', 'packages/boot/app-boot', 'vendor/cordis'];
47
+ ['@deepseek-ai/dsh', '@deepseek-ai/dsh-app-boot', '@deepseek-ai/cordis'].forEach((name, index) => manifest(root, paths[index], name));
48
+ manifest(root, 'packages/old/orphan', '@deepseek-ai/dsh-old');
49
+ const files = paths.map(path => path + '/package.json');
50
+ const discovered = discoverWorkspacePackages(root, [...files, 'packages/old/orphan/lib/package.json']);
51
+ assert.equal(discovered.size, 3);
52
+ assert.equal(discovered.has('@deepseek-ai/dsh-old'), false);
53
+ manifest(root, 'packages/boot/duplicate', '@deepseek-ai/dsh-app-boot');
54
+ assert.throws(() => discoverWorkspacePackages(root, [...files, 'packages/boot/duplicate/package.json']), /Duplicate/);
55
+ });
56
+
57
+ test('declared closure reports resolved versions and rejects a registry DSH duplicate', t => {
58
+ const root = sandbox(t);
59
+ const host = manifest(root, 'host', '@deepseek-ai/dsh', { dependencies: { '@deepseek-ai/dsh-agent': '*' } });
60
+ const actual = manifest(root, 'host/node_modules/@deepseek-ai/dsh-agent', '@deepseek-ai/dsh-agent');
61
+ const workspaces = new Map([
62
+ ['@deepseek-ai/dsh', { directory: host }],
63
+ ['@deepseek-ai/dsh-agent', { directory: actual }],
64
+ ]);
65
+ const result = inspectResolvedCohort(workspaces, [host]);
66
+ assert.equal(result.count, 2);
67
+ assert.equal(result.packages.find(pkg => pkg.name === '@deepseek-ai/dsh-agent').directory, actual);
68
+ assert.equal(result.edges[0].directory, actual);
69
+ workspaces.set('@deepseek-ai/dsh-agent', { directory: join(root, 'expected-source') });
70
+ assert.throws(() => inspectResolvedCohort(workspaces, [host]), /Mixed source closure/);
71
+ workspaces.delete('@deepseek-ai/dsh-agent');
72
+ assert.throws(() => inspectResolvedCohort(workspaces, [host]), /outside tracked source workspace/);
73
+ });
74
+
75
+ test('missing required dependencies fail while unavailable optional platforms remain explicit', t => {
76
+ const root = sandbox(t);
77
+ const host = manifest(root, 'host', '@deepseek-ai/dsh', { optionalDependencies: { 'missing-platform-addon': '1.0.0' } });
78
+ const workspaces = new Map([['@deepseek-ai/dsh', { directory: host }]]);
79
+ const result = inspectResolvedCohort(workspaces, [host]);
80
+ assert.equal(result.edges[0].missing, true);
81
+ assert.equal(result.edges[0].optional, true);
82
+ manifest(root, 'host', '@deepseek-ai/dsh', { dependencies: { 'missing-required-package': '1.0.0' } });
83
+ assert.throws(() => inspectResolvedCohort(workspaces, [host]), /Cannot resolve/);
84
+ });
85
+
86
+ test('closure reads the package identity when export maps hide or redirect package.json', t => {
87
+ const root = sandbox(t);
88
+ const host = manifest(root, 'host', '@deepseek-ai/dsh', { dependencies: { 'esm-only-library': '*', 'redirected-library': '*' } });
89
+ const esm = manifest(root, 'host/node_modules/esm-only-library', 'esm-only-library', { exports: { '.': { import: './entry.js' } } });
90
+ const redirected = manifest(root, 'host/node_modules/redirected-library', 'redirected-library', { exports: { './*': './dist/*' } });
91
+ mkdirSync(join(redirected, 'dist'));
92
+ writeFileSync(join(redirected, 'dist/package.json'), JSON.stringify({ type: 'commonjs' }));
93
+ const result = inspectResolvedCohort(new Map([['@deepseek-ai/dsh', { directory: host }]]), [host]);
94
+ assert.equal(result.packages.find(pkg => pkg.name === 'esm-only-library').directory, esm);
95
+ assert.equal(result.packages.find(pkg => pkg.name === 'redirected-library').directory, redirected);
96
+ assert.equal(result.packages.length, 3);
97
+ });
@@ -0,0 +1,68 @@
1
+ /** Shared execution plan and acceptance rules for real-host verification. */
2
+ import assert from 'node:assert/strict'
3
+ import { readFileSync } from 'node:fs'
4
+ import { join } from 'node:path'
5
+ import { pathToFileURL } from 'node:url'
6
+ import { policy, validatePolicy, validatePackageCompatibility } from './compatibility.mjs'
7
+
8
+ export const requiredRuntimeScenarios = [
9
+ 'lifecycle', 'lifecycle-cold-restore', 'fallback', 'fallback-cold-restore',
10
+ 'failure', 'captain-idle-wakeup', 'progressive-entry', 'web-approval',
11
+ 'protocol-compatibility', 'stability',
12
+ ]
13
+
14
+ export function hostVerification(version, support = policy) {
15
+ validatePolicy(support)
16
+ if (typeof version !== 'string' || !/^\d+\.\d+\.\d+(?:-(?:alpha|beta|rc)\.\d+)?$/.test(version)
17
+ || version.trim() !== version) throw new Error('Verification requires an exact host version')
18
+ const host = support.supportedHosts.find(host => host.version === version)
19
+ // Unknown candidates are tested before being added to support. They receive
20
+ // the full installation check, never the historical fixture-only exemption.
21
+ return {
22
+ platforms: host?.platforms ?? ['ubuntu-latest', 'windows-latest'],
23
+ pluginManagerInstall: host?.legacyDirectInstallReason === undefined,
24
+ ...(host?.legacyDirectInstallReason ? { legacyDirectInstallReason: host.legacyDirectInstallReason } : {}),
25
+ }
26
+ }
27
+
28
+ export function runtimeTargets(support = policy) {
29
+ return validatePolicy(support).flatMap(host => hostVerification(host, support).platforms.map(os => ({ host, os })))
30
+ }
31
+
32
+ export function validateRuntimeReport(report, target, expected, support = policy) {
33
+ const { host, os } = target
34
+ assert.ok(runtimeTargets(support).some(t => t.host === host && t.os === os), 'Report target is not in the verification plan')
35
+ assert.equal(report.passed, true, `Host ${host} did not pass`)
36
+ assert.equal(report.version, host)
37
+ assert.equal(report.platform, os === 'windows-latest' ? 'win32' : 'linux')
38
+ assert.equal(report.pluginVersion, expected.pluginVersion)
39
+ assert.equal(report.artifactSha256, expected.artifactSha256)
40
+ assert.ok(Array.isArray(report.runs) && report.runs.length > 0 && report.runs.every(run => run.passed === true), `Host ${host} lacks successful functional evidence`)
41
+ const required = [...requiredRuntimeScenarios, ...(hostVerification(host, support).pluginManagerInstall ? ['plugin-manager-install'] : [])]
42
+ for (const scenario of required) {
43
+ assert.ok(report.runs.some(run => run.scenario === scenario && run.passed === true), `Host ${host} did not exercise ${scenario}`)
44
+ }
45
+ }
46
+
47
+ export function validateRuntimeReports(directory, expected, support = policy) {
48
+ const targets = runtimeTargets(support)
49
+ for (const target of targets) {
50
+ const report = JSON.parse(readFileSync(join(directory, `harness-${target.os}-${target.host}`, 'result.json'), 'utf8'))
51
+ validateRuntimeReport(report, target, expected, support)
52
+ }
53
+ return targets.length
54
+ }
55
+
56
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
57
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
58
+ const hosts = validatePackageCompatibility(pkg)
59
+ if (process.argv.length === 3 && process.argv[2] === '--github-output') {
60
+ console.log(`targets=${JSON.stringify(runtimeTargets())}`)
61
+ } else if (process.argv.length === 6 && process.argv[2] === '--reports' && process.argv[4] === '--sha256') {
62
+ const artifactSha256 = process.argv[5]
63
+ assert.match(artifactSha256, /^[a-f0-9]{64}$/, 'Expected candidate SHA-256 is required')
64
+ if (process.env.EXPECTED_HOSTS) assert.deepEqual(hosts, JSON.parse(process.env.EXPECTED_HOSTS))
65
+ const count = validateRuntimeReports(process.argv[3], { pluginVersion: pkg.version, artifactSha256 })
66
+ console.log(`Verified one package against ${count} host/platform targets: ${hosts.join(', ')}`)
67
+ } else throw new Error('Usage: node scripts/harness-validation.mjs --github-output | --reports <directory> --sha256 <digest>')
68
+ }