@pi-unipi/background-tasks 2.6.2 → 2.6.4

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 (59) hide show
  1. package/package.json +3 -2
  2. package/src/tools.ts +3 -1
  3. package/src/__tests__/anthropic-attribution.test.ts +0 -195
  4. package/src/__tests__/config.test.ts +0 -137
  5. package/src/__tests__/core.test.ts +0 -493
  6. package/src/__tests__/delegate-artifacts.test.ts +0 -528
  7. package/src/__tests__/delegate-budget.test.ts +0 -456
  8. package/src/__tests__/delegate-launch.test.ts +0 -676
  9. package/src/__tests__/delegate-result-package.test.ts +0 -350
  10. package/src/__tests__/delegate-seed.test.ts +0 -392
  11. package/src/__tests__/durable-fs.test.ts +0 -559
  12. package/src/__tests__/extension-api.test.ts +0 -579
  13. package/src/__tests__/fusion-artifacts.test.ts +0 -1039
  14. package/src/__tests__/fusion-budget.test.ts +0 -1356
  15. package/src/__tests__/fusion-claude-cache.test.ts +0 -320
  16. package/src/__tests__/fusion-config.test.ts +0 -335
  17. package/src/__tests__/fusion-context-prompts.test.ts +0 -670
  18. package/src/__tests__/fusion-evaluation.test.ts +0 -315
  19. package/src/__tests__/fusion-extraction-equivalence.test.ts +0 -58
  20. package/src/__tests__/fusion-golden-bytes.test.ts +0 -35
  21. package/src/__tests__/fusion-high-cardinality.test.ts +0 -192
  22. package/src/__tests__/fusion-model-selector.test.ts +0 -205
  23. package/src/__tests__/fusion-orchestrator.test.ts +0 -1194
  24. package/src/__tests__/fusion-rpc.test.ts +0 -369
  25. package/src/__tests__/fusion-sdk.test.ts +0 -1226
  26. package/src/__tests__/fusion-v5-core.test.ts +0 -219
  27. package/src/__tests__/fusion-validate-orchestrator.test.ts +0 -240
  28. package/src/__tests__/fusion-web-fetch.test.ts +0 -485
  29. package/src/__tests__/fusion-workflows.test.ts +0 -59
  30. package/src/__tests__/helpers/delegate-deterministic-seed.ts +0 -109
  31. package/src/__tests__/helpers/delegate-seed-subprocess.ts +0 -10
  32. package/src/__tests__/helpers/fusion-canonical-subprocess.ts +0 -21
  33. package/src/__tests__/helpers/fusion-canonical.ts +0 -140
  34. package/src/__tests__/helpers/fusion-fake-pi.ts +0 -279
  35. package/src/__tests__/helpers/fusion-golden-corpus.ts +0 -500
  36. package/src/__tests__/helpers/fusion-high-cardinality.ts +0 -140
  37. package/src/__tests__/helpers/normalize.ts +0 -22
  38. package/src/__tests__/helpers/pi-hook-contract-evidence.json +0 -18
  39. package/src/__tests__/pi-launch.test.ts +0 -202
  40. package/src/__tests__/registry.test.ts +0 -1580
  41. package/src/__tests__/scripted-provider/delegate-ambient-provider.test.ts +0 -130
  42. package/src/__tests__/scripted-provider/delegate-child-guard.test.ts +0 -631
  43. package/src/__tests__/scripted-provider/delegate-guard-provider.ts +0 -403
  44. package/src/__tests__/scripted-provider/follow-up.test.ts +0 -448
  45. package/src/__tests__/scripted-provider/fusion-output-recovery.test.ts +0 -132
  46. package/src/__tests__/scripted-provider/fusion-reason.test.ts +0 -310
  47. package/src/__tests__/scripted-provider/fusion-runtime-guard.test.ts +0 -163
  48. package/src/__tests__/scripted-provider/hook-contract-provider.ts +0 -179
  49. package/src/__tests__/scripted-provider/hook-probe-a.ts +0 -3
  50. package/src/__tests__/scripted-provider/hook-probe-b.ts +0 -3
  51. package/src/__tests__/scripted-provider/hook-probe-extension.ts +0 -126
  52. package/src/__tests__/scripted-provider/output-recovery-provider.ts +0 -153
  53. package/src/__tests__/scripted-provider/pi-hook-contract-evidence.json +0 -18
  54. package/src/__tests__/scripted-provider/pi-hook-contract.test.ts +0 -477
  55. package/src/__tests__/scripted-provider/runtime-guard-probe.ts +0 -28
  56. package/src/__tests__/scripted-provider/runtime-guard-provider.ts +0 -49
  57. package/src/__tests__/scripted-provider/scripted-provider-extension.ts +0 -408
  58. package/src/__tests__/task-manager.test.ts +0 -479
  59. package/src/__tests__/windows-taskkill.test.ts +0 -161
@@ -1,202 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { readFileSync, realpathSync, statSync } from 'node:fs';
4
- import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
5
- import { dirname, join } from 'node:path';
6
- import { tmpdir } from 'node:os';
7
- import {
8
- assertWindowsCommandLineWithinLimit,
9
- piLaunchArgv,
10
- resolvePiLaunch,
11
- type PiLaunchDependencies,
12
- type PiLaunchSpec,
13
- } from '../pi-launch.js';
14
-
15
- interface PackageFixture {
16
- readonly root: string;
17
- readonly packageRoot: string;
18
- readonly manifestPath: string;
19
- readonly deps: PiLaunchDependencies;
20
- }
21
-
22
- async function writeNestedFile(path: string, content = ''): Promise<void> {
23
- await mkdir(dirname(path), { recursive: true });
24
- await writeFile(path, content, 'utf8');
25
- }
26
-
27
- function depsFor(manifestPath: string): PiLaunchDependencies {
28
- return {
29
- platform: 'win32',
30
- execPath: process.execPath,
31
- resolvePackageJson: () => manifestPath,
32
- readFile: (path) => readFileSync(path),
33
- realpath: (path) => realpathSync(path),
34
- stat: (path) => statSync(path),
35
- };
36
- }
37
-
38
- async function createPackageFixture(
39
- manifest: unknown,
40
- files: readonly string[],
41
- ): Promise<PackageFixture> {
42
- const root = await mkdtemp(join(tmpdir(), 'pi-bg-launch-'));
43
- const packageRoot = join(root, 'node_modules', '@earendil-works', 'pi-coding-agent');
44
- const manifestPath = join(packageRoot, 'package.json');
45
- await mkdir(packageRoot, { recursive: true });
46
- await writeFile(manifestPath, `${JSON.stringify(manifest)}\n`, 'utf8');
47
- for (const file of files) await writeNestedFile(join(packageRoot, file));
48
- return { root, packageRoot, manifestPath, deps: depsFor(manifestPath) };
49
- }
50
-
51
- async function removeFixture(root: string): Promise<void> {
52
- await rm(root, { recursive: true, force: true });
53
- }
54
-
55
- void describe('Pi launch resolution', () => {
56
- void it('returns the bare path form on POSIX without package lookup', () => {
57
- let resolved = false;
58
- const spec = resolvePiLaunch({
59
- platform: 'darwin',
60
- resolvePackageJson: () => {
61
- resolved = true;
62
- throw new Error('should not run');
63
- },
64
- });
65
- assert.deepEqual(spec, { executable: 'pi', argvPrefix: [], kind: 'path' });
66
- assert.equal(resolved, false);
67
- });
68
-
69
- void it('resolves a Windows string bin JavaScript CLI through Node', async () => {
70
- const fixture = await createPackageFixture({ bin: 'dist/cli.js' }, ['dist/cli.js']);
71
- try {
72
- const spec = resolvePiLaunch(fixture.deps);
73
- assert.equal(spec.executable, process.execPath);
74
- assert.equal(spec.kind, 'package-node-cli');
75
- assert.equal(spec.argvPrefix.length, 1);
76
- const cli = spec.argvPrefix[0];
77
- assert.ok(cli);
78
- assert.equal(cli, realpathSync(join(fixture.packageRoot, 'dist', 'cli.js')));
79
- assert.deepEqual(piLaunchArgv(spec, ['--mode', 'json']), [cli, '--mode', 'json']);
80
- } finally {
81
- await removeFixture(fixture.root);
82
- }
83
- });
84
-
85
- void it('resolves a Windows object bin JavaScript CLI through Node', async () => {
86
- const fixture = await createPackageFixture({ bin: { pi: 'dist/cli.cjs' } }, ['dist/cli.cjs']);
87
- try {
88
- const spec = resolvePiLaunch(fixture.deps);
89
- assert.equal(spec.executable, process.execPath);
90
- assert.equal(spec.argvPrefix.length, 1);
91
- assert.equal(spec.argvPrefix[0], realpathSync(join(fixture.packageRoot, 'dist', 'cli.cjs')));
92
- } finally {
93
- await removeFixture(fixture.root);
94
- }
95
- });
96
-
97
- void it('permits direct Windows native executable package bins', async () => {
98
- for (const extension of ['.exe', '.com']) {
99
- const file = `dist/pi${extension}`;
100
- const fixture = await createPackageFixture({ bin: { pi: file } }, [file]);
101
- try {
102
- const spec = resolvePiLaunch(fixture.deps);
103
- assert.equal(spec.executable, realpathSync(join(fixture.packageRoot, file)));
104
- assert.deepEqual(spec.argvPrefix, []);
105
- } finally {
106
- await removeFixture(fixture.root);
107
- }
108
- }
109
- });
110
-
111
- void it('rejects command shims, scripts, extensionless targets, and unknown extensions', async () => {
112
- for (const extension of ['.cmd', '.bat', '.ps1', '', '.txt']) {
113
- const file = `dist/pi${extension}`;
114
- const fixture = await createPackageFixture({ bin: { pi: file } }, [file]);
115
- try {
116
- assert.throws(
117
- () => resolvePiLaunch(fixture.deps),
118
- /pi_executable_resolution_failed: Pi package bin target extension is unsupported/,
119
- );
120
- } finally {
121
- await removeFixture(fixture.root);
122
- }
123
- }
124
- });
125
-
126
- void it('rejects package bin targets that escape the package root', async () => {
127
- const fixture = await createPackageFixture({ bin: '../outside/cli.js' }, []);
128
- try {
129
- await writeNestedFile(join(fixture.packageRoot, '..', 'outside', 'cli.js'));
130
- assert.throws(
131
- () => resolvePiLaunch(fixture.deps),
132
- /pi_executable_resolution_failed: Pi package bin target resolves outside the package root/,
133
- );
134
- } finally {
135
- await removeFixture(fixture.root);
136
- }
137
- });
138
-
139
- void it('rejects malformed manifests, missing manifests, missing bins, and non-file targets', async () => {
140
- const malformed = await createPackageFixture({ bin: 'dist/cli.js' }, ['dist/cli.js']);
141
- try {
142
- await writeFile(malformed.manifestPath, '{', 'utf8');
143
- assert.throws(() => resolvePiLaunch(malformed.deps), /pi_executable_resolution_failed/);
144
- } finally {
145
- await removeFixture(malformed.root);
146
- }
147
-
148
- const missingRoot = await mkdtemp(join(tmpdir(), 'pi-bg-launch-missing-'));
149
- try {
150
- const missingManifest = join(missingRoot, 'package.json');
151
- assert.throws(() => resolvePiLaunch(depsFor(missingManifest)), /pi_executable_resolution_failed/);
152
- } finally {
153
- await rm(missingRoot, { recursive: true, force: true });
154
- }
155
-
156
- const missingBin = await createPackageFixture({}, []);
157
- try {
158
- assert.throws(() => resolvePiLaunch(missingBin.deps), /pi_executable_resolution_failed/);
159
- } finally {
160
- await removeFixture(missingBin.root);
161
- }
162
-
163
- const directoryTarget = await createPackageFixture({ bin: 'dist/cli.js' }, []);
164
- try {
165
- await mkdir(join(directoryTarget.packageRoot, 'dist', 'cli.js'), { recursive: true });
166
- assert.throws(() => resolvePiLaunch(directoryTarget.deps), /regular file/);
167
- } finally {
168
- await removeFixture(directoryTarget.root);
169
- }
170
- });
171
-
172
- void it('rejects oversized Windows command lines without leaking argument text', () => {
173
- const launch: PiLaunchSpec = {
174
- executable: 'C:\\Node\\node.exe',
175
- argvPrefix: ['C:\\pkg\\cli.js'],
176
- kind: 'package-node-cli',
177
- };
178
- assert.doesNotThrow(() =>
179
- assertWindowsCommandLineWithinLimit(launch, ['--model', 'gpt-5.5'], 'win32', 'unit-stage'),
180
- );
181
- const secret = 'SECRET_TOKEN_VALUE';
182
- assert.throws(
183
- () =>
184
- assertWindowsCommandLineWithinLimit(
185
- launch,
186
- [secret.repeat(3000)],
187
- 'win32',
188
- 'oversized-stage',
189
- ),
190
- (error: unknown) => {
191
- assert.ok(error instanceof Error);
192
- assert.match(error.message, /oversized-stage/);
193
- assert.match(error.message, /32767/);
194
- assert.doesNotMatch(error.message, /SECRET_TOKEN_VALUE/);
195
- return true;
196
- },
197
- );
198
- assert.doesNotThrow(() =>
199
- assertWindowsCommandLineWithinLimit(launch, [secret.repeat(3000)], 'linux', 'posix-stage'),
200
- );
201
- });
202
- });