@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,130 +0,0 @@
1
- import { afterEach, describe, it } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { spawn } from 'node:child_process';
4
- import { existsSync } from 'node:fs';
5
- import { mkdir, mkdtemp, readFile, rm, symlink } from 'node:fs/promises';
6
- import { tmpdir } from 'node:os';
7
- import { join, resolve } from 'node:path';
8
- import { prepareDelegateLaunch } from '../../delegate/runner.js';
9
- import { loadDelegateHookContractEvidence } from '../../delegate/launch.js';
10
- import type { DelegateExtensionMode } from '../../delegate/types.js';
11
- import { sessionWith, userMessage } from '../helpers/fusion-canonical.js';
12
- import { isolatedTestEnv } from '../helpers/normalize.js';
13
-
14
- /**
15
- * Fresh-process regression for extension-registered delegate providers.
16
- *
17
- * The provider exists only as an auto-discovered global extension in a temp Pi
18
- * agent directory. It is never passed through `--extension`, so isolated mode
19
- * cannot resolve it while explicit ambient mode can. The ambient child still
20
- * receives the package guard and every non-extension isolation flag from the
21
- * production argv builder.
22
- */
23
- const roots: string[] = [];
24
- const providerExtension = resolve('tests/scripted-provider/delegate-guard-provider.ts');
25
- const piExecutable = resolve('node_modules/.bin/pi');
26
-
27
- async function runChild(
28
- mode: DelegateExtensionMode,
29
- ): Promise<{ code: number | null; stderr: string; artifactDir: string; argv: readonly string[] }> {
30
- const root = await mkdtemp(join(tmpdir(), `pi-bg-delegate-${mode}-`));
31
- roots.push(root);
32
- const cwd = join(root, 'project');
33
- const agentDir = join(root, 'agent');
34
- const extensionsDir = join(agentDir, 'extensions');
35
- await mkdir(cwd, { recursive: true });
36
- await mkdir(extensionsDir, { recursive: true });
37
- // A symlink keeps package imports resolving from this repository while still
38
- // exercising Pi's global ambient-extension discovery path.
39
- await symlink(providerExtension, join(extensionsDir, 'custom-provider.ts'));
40
-
41
- const evidenceRaw = await readFile(
42
- resolve('src/core/delegate/hook-contract-evidence.json'),
43
- 'utf8',
44
- );
45
- const prepared = await prepareDelegateLaunch({
46
- ctx: {
47
- cwd,
48
- sessionManager: sessionWith([userMessage('ambient provider regression')]),
49
- getSystemPrompt: () => 'parent system prompt',
50
- },
51
- toolCallId: 'ambient-provider-call',
52
- prompt: 'Return the deterministic delegate answer.',
53
- capability: 'inspect',
54
- extensionMode: mode,
55
- route: {
56
- provider: 'pi-bg-delegate',
57
- model: 'delegate-model',
58
- qualified_id: 'pi-bg-delegate/delegate-model',
59
- context_window_tokens: 200_000,
60
- thinking_level: 'medium',
61
- origin: 'explicit',
62
- },
63
- limitOverrides: { maxTurns: 4, maxToolCalls: 8, timeoutSeconds: 30 },
64
- hookEvidence: loadDelegateHookContractEvidence(evidenceRaw),
65
- cwd,
66
- sessionId: `ambient-provider-${mode}`,
67
- autoDeliver: 'never',
68
- env: {
69
- ...process.env,
70
- ...isolatedTestEnv,
71
- PI_CODING_AGENT_DIR: agentDir,
72
- UNIPI_BG_DELEGATE_API_KEY: 'delegate-api-key',
73
- UNIPI_BG_DELEGATE_SCENARIO: 'plain-answer',
74
- },
75
- });
76
-
77
- const result = await new Promise<{ code: number | null; stderr: string }>((resolveResult, reject) => {
78
- const child = spawn(piExecutable, [...prepared.argv], {
79
- cwd,
80
- env: prepared.env,
81
- stdio: ['pipe', 'ignore', 'pipe'],
82
- });
83
- let stderr = '';
84
- child.stderr.setEncoding('utf8');
85
- child.stderr.on('data', (chunk: string) => {
86
- stderr += chunk;
87
- });
88
- child.once('error', reject);
89
- child.once('close', (code) => resolveResult({ code, stderr }));
90
- child.stdin.end(prepared.stdinBytes);
91
- });
92
-
93
- return {
94
- ...result,
95
- artifactDir: prepared.store.artifactDirAbs,
96
- argv: prepared.argv,
97
- };
98
- }
99
-
100
- afterEach(async () => {
101
- for (const root of roots.splice(0)) await rm(root, { recursive: true, force: true });
102
- });
103
-
104
- void describe('delegate ambient extension provider discovery', { concurrency: false }, () => {
105
- void it(
106
- 'fails closed in isolated mode and resolves the same pinned provider in ambient mode',
107
- { timeout: 60_000 },
108
- async () => {
109
- const isolated = await runChild('isolated');
110
- assert.notEqual(isolated.code, 0);
111
- assert.match(isolated.stderr, /Unknown provider "pi-bg-delegate"/);
112
- assert.ok(isolated.argv.includes('--no-extensions'));
113
- assert.equal(existsSync(join(isolated.artifactDir, 'result.json')), false);
114
-
115
- const ambient = await runChild('ambient');
116
- assert.equal(ambient.code, 0, ambient.stderr);
117
- assert.ok(!ambient.argv.includes('--no-extensions'));
118
- assert.ok(ambient.argv.includes('--no-skills'));
119
- assert.ok(ambient.argv.includes('--no-prompt-templates'));
120
- assert.ok(ambient.argv.includes('--no-themes'));
121
- assert.ok(ambient.argv.includes('--no-context-files'));
122
- const explicitExtensions = ambient.argv.flatMap((entry, index) =>
123
- entry === '--extension' ? [ambient.argv[index + 1] ?? ''] : [],
124
- );
125
- assert.equal(explicitExtensions.length, 1);
126
- assert.match(explicitExtensions[0] ?? '', /extensions\/delegate-child\.(?:ts|js)$/);
127
- assert.ok(existsSync(join(ambient.artifactDir, 'result.json')));
128
- },
129
- );
130
- });