@principles/pd-cli 1.147.16 → 1.148.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.
- package/dist/commands/pain-list.d.ts +14 -0
- package/dist/commands/pain-list.d.ts.map +1 -1
- package/dist/commands/pain-list.js +28 -1
- package/dist/commands/pain-list.js.map +1 -1
- package/dist/commands/pain-record.d.ts +2 -0
- package/dist/commands/pain-record.d.ts.map +1 -1
- package/dist/commands/pain-record.js +71 -4
- package/dist/commands/pain-record.js.map +1 -1
- package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/dist/commands/runtime-internalization-run-once.js +23 -7
- package/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.js +4 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +1 -1
- package/dist/services/resolve-runtime-from-pd-config.d.ts +28 -2
- package/dist/services/resolve-runtime-from-pd-config.d.ts.map +1 -1
- package/dist/services/resolve-runtime-from-pd-config.js +19 -6
- package/dist/services/resolve-runtime-from-pd-config.js.map +1 -1
- package/dist/services/rulehost-readiness.js +1 -1
- package/dist/services/rulehost-readiness.js.map +1 -1
- package/dist/services/runtime-adapter-resolver.d.ts +14 -1
- package/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
- package/dist/services/runtime-adapter-resolver.js +4 -1
- package/dist/services/runtime-adapter-resolver.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/pain-list.ts +37 -1
- package/src/commands/pain-record.ts +73 -4
- package/src/commands/runtime-internalization-run-once.ts +23 -7
- package/src/index.ts +1 -0
- package/src/services/__tests__/runtime-adapter-resolver.test.ts +4 -1
- package/src/services/resolve-runtime-from-pd-config.ts +44 -6
- package/src/services/rulehost-readiness.ts +1 -1
- package/src/services/runtime-adapter-resolver.ts +18 -2
- package/tests/commands/pain-list.test.ts +35 -1
- package/tests/commands/pain-record-session-parser.test.ts +27 -0
- package/tests/commands/pain-record.test.ts +77 -0
- package/tests/commands/pri-393-runtime-config-unification.test.ts +13 -11
- package/tests/commands/runtime-internalization-run-once-language.test.ts +12 -0
- package/tests/commands/runtime-internalization-run-once-real-config.test.ts +237 -0
- package/tests/commands/runtime-internalization-run-once.test.ts +21 -5
- package/tests/services/resolve-runtime-from-pd-config.test.ts +3 -3
|
@@ -119,8 +119,10 @@ describe('PRI-393: runtime config unification', () => {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
for (const block of importBlocks) {
|
|
122
|
-
// Allow
|
|
123
|
-
|
|
122
|
+
// Allow the canonical resolver family — resolveRuntimeConfigFromPdConfig
|
|
123
|
+
// (shared diagnostician binding) and resolveRuntimeConfigForAgent (the
|
|
124
|
+
// PRI-719 per-agent variant) — but NOT bare legacy resolveRuntimeConfig
|
|
125
|
+
if (block.includes('resolveRuntimeConfig') && !block.includes('resolveRuntimeConfigFromPdConfig') && !block.includes('resolveRuntimeConfigForAgent')) {
|
|
124
126
|
// This is the legacy import — fail
|
|
125
127
|
expect.fail(
|
|
126
128
|
`${file} still imports legacy resolveRuntimeConfig from @principles/core/runtime-v2. ` +
|
|
@@ -212,7 +214,7 @@ describe('PRI-393: runtime config unification', () => {
|
|
|
212
214
|
|
|
213
215
|
// Dynamically import to avoid module resolution issues
|
|
214
216
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
215
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => 'test-key');
|
|
217
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => 'test-key' });
|
|
216
218
|
|
|
217
219
|
expect(resolved.configSource).toBe('.pd/config.yaml');
|
|
218
220
|
expect(resolved.result).toBeDefined();
|
|
@@ -238,7 +240,7 @@ funnels:
|
|
|
238
240
|
`);
|
|
239
241
|
|
|
240
242
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
241
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => 'test-key');
|
|
243
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => 'test-key' });
|
|
242
244
|
|
|
243
245
|
// Should have legacy warning
|
|
244
246
|
expect(resolved.legacyWarnings.length).toBeGreaterThan(0);
|
|
@@ -259,7 +261,7 @@ funnels:
|
|
|
259
261
|
|
|
260
262
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
261
263
|
const { isRuntimeConfigError: isErr } = await import('@principles/core/runtime-v2');
|
|
262
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => 'test-key');
|
|
264
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => 'test-key' });
|
|
263
265
|
|
|
264
266
|
// Malformed config must produce a RuntimeConfigError — never fall back to defaults
|
|
265
267
|
expect(resolved.configLoadResult.ok).toBe(false);
|
|
@@ -277,7 +279,7 @@ funnels:
|
|
|
277
279
|
writeConfigYaml(tmpDir, makeValidConfigYaml());
|
|
278
280
|
|
|
279
281
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
280
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => 'test-key');
|
|
282
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => 'test-key' });
|
|
281
283
|
|
|
282
284
|
const jsonStr = JSON.stringify(resolved.result);
|
|
283
285
|
const parsed = JSON.parse(jsonStr);
|
|
@@ -355,7 +357,7 @@ funnels:
|
|
|
355
357
|
it('handles empty workspace directory gracefully', async () => {
|
|
356
358
|
// No .pd directory at all
|
|
357
359
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
358
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => 'test-key');
|
|
360
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => 'test-key' });
|
|
359
361
|
|
|
360
362
|
// Missing config should return defaults (ok=true with source='defaults')
|
|
361
363
|
expect(resolved.configLoadResult.ok).toBe(true);
|
|
@@ -371,7 +373,7 @@ funnels:
|
|
|
371
373
|
|
|
372
374
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
373
375
|
const { isRuntimeConfigError } = await import('@principles/core/runtime-v2');
|
|
374
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => 'test-key');
|
|
376
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => 'test-key' });
|
|
375
377
|
|
|
376
378
|
// Missing runtimeProfiles should either load with defaults or produce
|
|
377
379
|
// a RuntimeConfigError — never silently succeed with wrong config.
|
|
@@ -400,7 +402,7 @@ funnels:
|
|
|
400
402
|
|
|
401
403
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
402
404
|
const { isRuntimeConfigError } = await import('@principles/core/runtime-v2');
|
|
403
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => 'test-key');
|
|
405
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => 'test-key' });
|
|
404
406
|
|
|
405
407
|
// Invalid type should be caught — verify external contract, not internal state
|
|
406
408
|
expect(isRuntimeConfigError(resolved.result)).toBe(true);
|
|
@@ -414,7 +416,7 @@ funnels:
|
|
|
414
416
|
writeConfigYaml(tmpDir, makeValidConfigYaml());
|
|
415
417
|
|
|
416
418
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
417
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => undefined);
|
|
419
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => undefined });
|
|
418
420
|
|
|
419
421
|
// Should handle undefined env var gracefully
|
|
420
422
|
expect(resolved.result).toBeDefined();
|
|
@@ -432,7 +434,7 @@ funnels:
|
|
|
432
434
|
fs.writeFileSync(path.join(ffDir, 'feature-flags.yaml'), 'flags: []', 'utf8');
|
|
433
435
|
|
|
434
436
|
const { resolveRuntimeFromPdConfig } = await import('../../src/services/resolve-runtime-from-pd-config.js');
|
|
435
|
-
const resolved = resolveRuntimeFromPdConfig(tmpDir, () => 'test-key');
|
|
437
|
+
const resolved = resolveRuntimeFromPdConfig(tmpDir, { getEnvVar: () => 'test-key' });
|
|
436
438
|
|
|
437
439
|
expect(resolved.legacyWarnings.length).toBeGreaterThan(0);
|
|
438
440
|
expect(resolved.configLoadResult.legacyFilesDetected.length).toBeGreaterThanOrEqual(2);
|
|
@@ -187,6 +187,18 @@ vi.mock('@principles/core/runtime-v2', () => ({
|
|
|
187
187
|
return { validate: vi.fn().mockResolvedValue({ valid: true, errors: [] }) };
|
|
188
188
|
}),
|
|
189
189
|
resolveRuntimeConfigFromPdConfig: vi.fn().mockReturnValue({ runtimeKind: 'pi-ai', provider: 'test-provider', model: 'test-model', apiKeyEnv: 'TEST_API_KEY', timeoutMs: 300_000, agentId: 'main' }),
|
|
190
|
+
// PRI-719: run-once resolves the SELECTED runner's agent binding through
|
|
191
|
+
// the per-agent variant; mirror the real taskKind→agent mapping (whole
|
|
192
|
+
// core module is mocked here).
|
|
193
|
+
resolveRuntimeConfigForAgent: vi.fn().mockReturnValue({ runtimeKind: 'pi-ai', provider: 'test-provider', model: 'test-model', apiKeyEnv: 'TEST_API_KEY', timeoutMs: 300_000, agentId: 'main' }),
|
|
194
|
+
AGENT_NAME_FOR_TASK_KIND: {
|
|
195
|
+
dreamer: 'dreamer',
|
|
196
|
+
philosopher: 'philosopher',
|
|
197
|
+
scribe: 'scribe',
|
|
198
|
+
artificer: 'artificer',
|
|
199
|
+
evaluator: 'evaluator',
|
|
200
|
+
rollout_reviewer: 'rolloutReviewer',
|
|
201
|
+
},
|
|
190
202
|
resolveRuntimeConfig: vi.fn().mockReturnValue({ runtimeKind: 'pi-ai', timeoutMs: 300_000, agentId: 'main', provider: 'test-provider', model: 'test-model', apiKeyEnv: 'TEST_API_KEY' }),
|
|
191
203
|
validateRuntimeConfig: vi.fn(),
|
|
192
204
|
isRuntimeConfigError: vi.fn().mockImplementation((result: unknown) => result != null && typeof result === 'object' && Object.hasOwn(result, 'reason') && !Object.hasOwn(result, 'runtimeKind')),
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-719 review — real-config composition tests (NO core module mock).
|
|
3
|
+
*
|
|
4
|
+
* The run-once unit suites mock `@principles/core/runtime-v2`, which cannot
|
|
5
|
+
* prove real default-config behavior. These tests drive the REAL resolver
|
|
6
|
+
* chain (resolveRuntimeFromPdConfig → resolveRuntimeConfigForAgent →
|
|
7
|
+
* resolveRuntimeAdapterFromConfig) against real workspaces built from
|
|
8
|
+
* `getDefaultPdConfig()`:
|
|
9
|
+
*
|
|
10
|
+
* Case 1 evaluator shipped disabled + explicit runtimeProfile → an
|
|
11
|
+
* explicit peer run-once resolves ITS profile (no
|
|
12
|
+
* "Agent 'evaluator' is disabled"), because peer execution scope
|
|
13
|
+
* is the internalization_full_chain flag — the same
|
|
14
|
+
* ignoreAgentEnabled semantics the auto-consumer uses.
|
|
15
|
+
* Case 2 rolloutReviewer shipped disabled — same resolution.
|
|
16
|
+
* Case 3 per-agent isolation: diagnostician→profile-A, evaluator→B;
|
|
17
|
+
* the run-once seam resolves profile-B.
|
|
18
|
+
* Case 4 the diagnostician bridge gate still HONORS enabled (no global
|
|
19
|
+
* bypass leaked from the peer option).
|
|
20
|
+
* B7 cross-entry equivalence: run-once path and auto-consumer path
|
|
21
|
+
* resolve IDENTICAL runtimeProfileId/provider/model for the same
|
|
22
|
+
* config (runtime binding must not drift across entry points).
|
|
23
|
+
*/
|
|
24
|
+
import { describe, expect, it } from 'vitest';
|
|
25
|
+
import fs from 'node:fs';
|
|
26
|
+
import os from 'node:os';
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
import {
|
|
29
|
+
computeEffectivePdConfig,
|
|
30
|
+
getDefaultPdConfig,
|
|
31
|
+
resolveRuntimeConfigForAgent,
|
|
32
|
+
AGENT_NAME_FOR_TASK_KIND,
|
|
33
|
+
type RuntimeConfigError,
|
|
34
|
+
} from '@principles/core/runtime-v2';
|
|
35
|
+
import { resolveRuntimeFromPdConfig } from '../../src/services/resolve-runtime-from-pd-config.js';
|
|
36
|
+
import { resolveRuntimeAdapterFromConfig } from '../../src/services/runtime-adapter-resolver.js';
|
|
37
|
+
|
|
38
|
+
const dirs: string[] = [];
|
|
39
|
+
|
|
40
|
+
function makeWorkspace(): string {
|
|
41
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-runonce-profile-'));
|
|
42
|
+
dirs.push(root);
|
|
43
|
+
fs.mkdirSync(path.join(root, '.pd'), { recursive: true });
|
|
44
|
+
return root;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function writeProfileConfig(root: string, agents: Record<string, string>): void {
|
|
48
|
+
const config = getDefaultPdConfig();
|
|
49
|
+
(config.runtimeProfiles as Record<string, unknown>) = {
|
|
50
|
+
...(config.runtimeProfiles as Record<string, unknown>),
|
|
51
|
+
'profile-diagnostician': {
|
|
52
|
+
type: 'pi-ai', provider: 'prov-diag', model: 'diag-model', apiKeyEnv: 'DIAG_KEY',
|
|
53
|
+
baseUrl: 'http://127.0.0.1:9001/v1',
|
|
54
|
+
},
|
|
55
|
+
'profile-evaluator': {
|
|
56
|
+
type: 'pi-ai', provider: 'prov-evaluator', model: 'evaluator-model', apiKeyEnv: 'EVAL_KEY',
|
|
57
|
+
baseUrl: 'http://127.0.0.1:9002/v1',
|
|
58
|
+
},
|
|
59
|
+
'profile-rollout': {
|
|
60
|
+
type: 'pi-ai', provider: 'prov-rollout', model: 'rollout-model', apiKeyEnv: 'ROLLOUT_KEY',
|
|
61
|
+
baseUrl: 'http://127.0.0.1:9003/v1',
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const agentBindings = config.internalAgents.agents as Record<string, { enabled: boolean; runtimeProfile?: string }>;
|
|
65
|
+
// The shipped default config pins every agent's runtimeProfile — replace
|
|
66
|
+
// the DECLARED profiles per the scenario; enabled flags stay at their
|
|
67
|
+
// shipped values (evaluator/rolloutReviewer/philosopher = false).
|
|
68
|
+
for (const [agent, profileId] of Object.entries(agents)) {
|
|
69
|
+
agentBindings[agent] = { ...agentBindings[agent], runtimeProfile: profileId };
|
|
70
|
+
}
|
|
71
|
+
// JSON is valid YAML — same trick the sibling composition tests use.
|
|
72
|
+
fs.writeFileSync(path.join(root, '.pd', 'config.yaml'), JSON.stringify(config));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function readAdapterConfig(adapter: unknown): { provider?: string; model?: string } {
|
|
76
|
+
return (adapter as unknown as { config: { provider?: string; model?: string } }).config;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isErr(result: unknown): RuntimeConfigError {
|
|
80
|
+
return result as RuntimeConfigError;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('PRI-719 review — explicit run-once resolves shipped-disabled peer agents on their own profile (real config)', () => {
|
|
84
|
+
it('Case 1: evaluator enabled=false (default) + declared profile → run-once seam resolves profile-evaluator', () => {
|
|
85
|
+
const ws = makeWorkspace();
|
|
86
|
+
writeProfileConfig(ws, { evaluator: 'profile-evaluator' });
|
|
87
|
+
process.env.EVAL_KEY = 'test-key';
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const resolved = resolveRuntimeFromPdConfig(ws, {
|
|
91
|
+
agentName: 'evaluator',
|
|
92
|
+
ignoreAgentEnabled: true,
|
|
93
|
+
});
|
|
94
|
+
expect(resolved.result).not.toHaveProperty('ok');
|
|
95
|
+
if (resolved.result.ok === false) return;
|
|
96
|
+
expect(resolved.result.runtimeKind).toBe('pi-ai');
|
|
97
|
+
expect(resolved.result.provider).toBe('prov-evaluator');
|
|
98
|
+
expect(resolved.result.model).toBe('evaluator-model');
|
|
99
|
+
expect(resolved.result.runtimeProfileId).toBe('profile-evaluator');
|
|
100
|
+
|
|
101
|
+
// The run-once ADAPTER seam resolves the same profile into the adapter.
|
|
102
|
+
const adapter = resolveRuntimeAdapterFromConfig({
|
|
103
|
+
runtimeKind: 'config',
|
|
104
|
+
workspaceDir: ws,
|
|
105
|
+
runnerKind: 'evaluator',
|
|
106
|
+
agentName: 'evaluator',
|
|
107
|
+
ignoreAgentEnabled: true,
|
|
108
|
+
});
|
|
109
|
+
// The real (unmocked) adapter has no `__type` marker — assert via kind().
|
|
110
|
+
expect(adapter.kind()).toBe('pi-ai');
|
|
111
|
+
expect(readAdapterConfig(adapter)).toMatchObject({
|
|
112
|
+
provider: 'prov-evaluator', model: 'evaluator-model',
|
|
113
|
+
});
|
|
114
|
+
} finally {
|
|
115
|
+
delete process.env.EVAL_KEY;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('Case 2: rolloutReviewer enabled=false (default) → run-once seam resolves profile-rollout', () => {
|
|
120
|
+
const ws = makeWorkspace();
|
|
121
|
+
writeProfileConfig(ws, { rolloutReviewer: 'profile-rollout' });
|
|
122
|
+
process.env.ROLLOUT_KEY = 'test-key';
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
// Through the canonical taskKind→agent map, as run-once does.
|
|
126
|
+
const agentName = AGENT_NAME_FOR_TASK_KIND['rollout_reviewer'];
|
|
127
|
+
expect(agentName).toBe('rolloutReviewer');
|
|
128
|
+
const resolved = resolveRuntimeFromPdConfig(ws, { agentName, ignoreAgentEnabled: true });
|
|
129
|
+
if (resolved.result.ok === false) throw new Error(resolved.result.message);
|
|
130
|
+
expect(resolved.result.provider).toBe('prov-rollout');
|
|
131
|
+
expect(resolved.result.runtimeProfileId).toBe('profile-rollout');
|
|
132
|
+
} finally {
|
|
133
|
+
delete process.env.ROLLOUT_KEY;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('Case 3: per-agent isolation — evaluator resolves ITS profile, not the diagnostician one', () => {
|
|
138
|
+
const ws = makeWorkspace();
|
|
139
|
+
writeProfileConfig(ws, { diagnostician: 'profile-diagnostician', evaluator: 'profile-evaluator' });
|
|
140
|
+
process.env.DIAG_KEY = 'test-key';
|
|
141
|
+
process.env.EVAL_KEY = 'test-key';
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
const adapter = resolveRuntimeAdapterFromConfig({
|
|
145
|
+
runtimeKind: 'config',
|
|
146
|
+
workspaceDir: ws,
|
|
147
|
+
runnerKind: 'evaluator',
|
|
148
|
+
agentName: 'evaluator',
|
|
149
|
+
ignoreAgentEnabled: true,
|
|
150
|
+
});
|
|
151
|
+
expect(readAdapterConfig(adapter)).toMatchObject({
|
|
152
|
+
provider: 'prov-evaluator', model: 'evaluator-model',
|
|
153
|
+
});
|
|
154
|
+
} finally {
|
|
155
|
+
delete process.env.DIAG_KEY;
|
|
156
|
+
delete process.env.EVAL_KEY;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('negative control: without ignoreAgentEnabled the shipped-disabled evaluator still refuses', () => {
|
|
161
|
+
const ws = makeWorkspace();
|
|
162
|
+
writeProfileConfig(ws, { evaluator: 'profile-evaluator' });
|
|
163
|
+
process.env.EVAL_KEY = 'test-key';
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
// Pins that the option (not something else) lifts the gate: the same
|
|
167
|
+
// call without it honors enabled and refuses.
|
|
168
|
+
expect(() => resolveRuntimeAdapterFromConfig({
|
|
169
|
+
runtimeKind: 'config',
|
|
170
|
+
workspaceDir: ws,
|
|
171
|
+
runnerKind: 'evaluator',
|
|
172
|
+
agentName: 'evaluator',
|
|
173
|
+
})).toThrow(/disabled/);
|
|
174
|
+
} finally {
|
|
175
|
+
delete process.env.EVAL_KEY;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('Case 4: diagnostician bridge gate still HONORS enabled (no global bypass)', () => {
|
|
180
|
+
const ws = makeWorkspace();
|
|
181
|
+
writeProfileConfig(ws, { diagnostician: 'profile-diagnostician' });
|
|
182
|
+
process.env.DIAG_KEY = 'test-key';
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const config = JSON.parse(fs.readFileSync(path.join(ws, '.pd', 'config.yaml'), 'utf8'));
|
|
186
|
+
config.internalAgents.agents.diagnostician.enabled = false;
|
|
187
|
+
fs.writeFileSync(path.join(ws, '.pd', 'config.yaml'), JSON.stringify(config));
|
|
188
|
+
|
|
189
|
+
// Canonical diagnostician resolution (the pain-signal bridge path)
|
|
190
|
+
// keeps failing closed with readiness=disabled.
|
|
191
|
+
const viaWrapper = resolveRuntimeFromPdConfig(ws);
|
|
192
|
+
expect(viaWrapper.result).toHaveProperty('ok', false);
|
|
193
|
+
expect(isErr(viaWrapper.result).reason).toBe('disabled');
|
|
194
|
+
|
|
195
|
+
const viaCore = resolveRuntimeConfigForAgent(
|
|
196
|
+
computeEffectivePdConfig(config),
|
|
197
|
+
'diagnostician',
|
|
198
|
+
{ getEnvVar: (name) => process.env[name] },
|
|
199
|
+
);
|
|
200
|
+
expect(viaCore).toHaveProperty('ok', false);
|
|
201
|
+
expect(isErr(viaCore).reason).toBe('disabled');
|
|
202
|
+
} finally {
|
|
203
|
+
delete process.env.DIAG_KEY;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('B7 cross-entry equivalence: run-once path and auto-consumer path resolve the SAME binding', () => {
|
|
208
|
+
const ws = makeWorkspace();
|
|
209
|
+
writeProfileConfig(ws, { diagnostician: 'profile-diagnostician', evaluator: 'profile-evaluator' });
|
|
210
|
+
process.env.EVAL_KEY = 'test-key';
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
// Auto-consumer path: per-kind resolution with peer scope semantics.
|
|
214
|
+
const consumerResult = resolveRuntimeConfigForAgent(
|
|
215
|
+
computeEffectivePdConfig(JSON.parse(fs.readFileSync(path.join(ws, '.pd', 'config.yaml'), 'utf8'))),
|
|
216
|
+
'evaluator',
|
|
217
|
+
{ getEnvVar: (name) => process.env[name], ignoreAgentEnabled: true },
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// Explicit run-once path: resolveRuntimeFromPdConfig with the same
|
|
221
|
+
// agent + scope semantics (exactly what run-once's two resolution
|
|
222
|
+
// points use).
|
|
223
|
+
const runOnceResult = resolveRuntimeFromPdConfig(ws, {
|
|
224
|
+
agentName: 'evaluator',
|
|
225
|
+
ignoreAgentEnabled: true,
|
|
226
|
+
}).result;
|
|
227
|
+
|
|
228
|
+
expect(runOnceResult).toEqual(consumerResult);
|
|
229
|
+
if (runOnceResult.ok === false || consumerResult.ok === false) return;
|
|
230
|
+
expect(runOnceResult.runtimeProfileId).toBe('profile-evaluator');
|
|
231
|
+
expect(runOnceResult.provider).toBe('prov-evaluator');
|
|
232
|
+
expect(runOnceResult.model).toBe('evaluator-model');
|
|
233
|
+
} finally {
|
|
234
|
+
delete process.env.EVAL_KEY;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -163,6 +163,19 @@ vi.mock('@principles/core/runtime-v2', () => ({
|
|
|
163
163
|
isRuntimeConfigError: vi.fn().mockImplementation((result: unknown) => result != null && typeof result === 'object' && Object.hasOwn(result, 'reason') && !Object.hasOwn(result, 'runtimeKind')),
|
|
164
164
|
validateRuntimeConfig: vi.fn(),
|
|
165
165
|
resolveRuntimeConfigFromPdConfig: vi.fn().mockReturnValue({ runtimeKind: 'pi-ai', provider: 'test-provider', model: 'test-model', apiKeyEnv: 'TEST_API_KEY', timeoutMs: 300_000, agentId: 'main' }),
|
|
166
|
+
// PRI-719: run-once resolves the SELECTED runner's agent binding through
|
|
167
|
+
// the per-agent variant — this is the seam the PRI-670 timeout tests mock.
|
|
168
|
+
resolveRuntimeConfigForAgent: vi.fn().mockReturnValue({ runtimeKind: 'pi-ai', provider: 'test-provider', model: 'test-model', apiKeyEnv: 'TEST_API_KEY', timeoutMs: 300_000, agentId: 'main' }),
|
|
169
|
+
// PRI-719: the real taskKind→agent mapping (stable constant, mirrored here
|
|
170
|
+
// because the whole core module is mocked in this file).
|
|
171
|
+
AGENT_NAME_FOR_TASK_KIND: {
|
|
172
|
+
dreamer: 'dreamer',
|
|
173
|
+
philosopher: 'philosopher',
|
|
174
|
+
scribe: 'scribe',
|
|
175
|
+
artificer: 'artificer',
|
|
176
|
+
evaluator: 'evaluator',
|
|
177
|
+
rollout_reviewer: 'rolloutReviewer',
|
|
178
|
+
},
|
|
166
179
|
resolveOutputLanguage: vi.fn().mockReturnValue({ outputLanguage: 'zh-CN' }),
|
|
167
180
|
}));
|
|
168
181
|
|
|
@@ -508,9 +521,12 @@ describe('handleRuntimeInternalizationRunOnce', () => {
|
|
|
508
521
|
const customWs = '/tmp/test-workspace';
|
|
509
522
|
await handleRuntimeInternalizationRunOnce({ workspace: customWs, runtime: 'config', json: true });
|
|
510
523
|
|
|
511
|
-
// PRI-393:
|
|
524
|
+
// PRI-393 + PRI-719 (+review): resolveRuntimeFromPdConfig is called with
|
|
525
|
+
// the workspace dir AND the selected runner's agent binding under the
|
|
526
|
+
// PEER ignoreAgentEnabled semantics (same as the auto-consumer).
|
|
512
527
|
expect(mockResolveRuntimeFromPdConfig).toHaveBeenCalledWith(
|
|
513
528
|
expect.stringContaining('test-workspace'),
|
|
529
|
+
{ agentName: 'dreamer', ignoreAgentEnabled: true },
|
|
514
530
|
);
|
|
515
531
|
});
|
|
516
532
|
|
|
@@ -824,7 +840,7 @@ describe('handleRuntimeInternalizationRunOnce', () => {
|
|
|
824
840
|
// the PRI-670 fix the runner deadline stayed hardcoded at 300s and the
|
|
825
841
|
// profile value only reached the adapter as a per-request timeout.
|
|
826
842
|
const coreModule = await import('@principles/core/runtime-v2');
|
|
827
|
-
vi.mocked(coreModule.
|
|
843
|
+
vi.mocked(coreModule.resolveRuntimeConfigForAgent).mockReturnValue({
|
|
828
844
|
runtimeKind: 'pi-ai', provider: 'test-provider', model: 'test-model',
|
|
829
845
|
apiKeyEnv: 'TEST_API_KEY', timeoutMs: 600_000, agentId: 'main',
|
|
830
846
|
} as never);
|
|
@@ -857,7 +873,7 @@ describe('handleRuntimeInternalizationRunOnce', () => {
|
|
|
857
873
|
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
858
874
|
expect(output.effectiveTimeoutMs).toBe(600_000);
|
|
859
875
|
} finally {
|
|
860
|
-
vi.mocked(coreModule.
|
|
876
|
+
vi.mocked(coreModule.resolveRuntimeConfigForAgent).mockReturnValue({
|
|
861
877
|
runtimeKind: 'pi-ai', provider: 'test-provider', model: 'test-model',
|
|
862
878
|
apiKeyEnv: 'TEST_API_KEY', timeoutMs: 300_000, agentId: 'main',
|
|
863
879
|
} as never);
|
|
@@ -866,7 +882,7 @@ describe('handleRuntimeInternalizationRunOnce', () => {
|
|
|
866
882
|
|
|
867
883
|
it('PRI-670: --timeout-ms still wins over the profile timeoutMs', async () => {
|
|
868
884
|
const coreModule = await import('@principles/core/runtime-v2');
|
|
869
|
-
vi.mocked(coreModule.
|
|
885
|
+
vi.mocked(coreModule.resolveRuntimeConfigForAgent).mockReturnValue({
|
|
870
886
|
runtimeKind: 'pi-ai', provider: 'test-provider', model: 'test-model',
|
|
871
887
|
apiKeyEnv: 'TEST_API_KEY', timeoutMs: 600_000, agentId: 'main',
|
|
872
888
|
} as never);
|
|
@@ -892,7 +908,7 @@ describe('handleRuntimeInternalizationRunOnce', () => {
|
|
|
892
908
|
const output = JSON.parse(consoleLogSpy.mock.calls[0][0]);
|
|
893
909
|
expect(output.effectiveTimeoutMs).toBe(120_000);
|
|
894
910
|
} finally {
|
|
895
|
-
vi.mocked(coreModule.
|
|
911
|
+
vi.mocked(coreModule.resolveRuntimeConfigForAgent).mockReturnValue({
|
|
896
912
|
runtimeKind: 'pi-ai', provider: 'test-provider', model: 'test-model',
|
|
897
913
|
apiKeyEnv: 'TEST_API_KEY', timeoutMs: 300_000, agentId: 'main',
|
|
898
914
|
} as never);
|
|
@@ -114,7 +114,7 @@ describe('buildProfileLabel', () => {
|
|
|
114
114
|
},
|
|
115
115
|
}));
|
|
116
116
|
try {
|
|
117
|
-
const result = resolveRuntimeFromPdConfig(tmp, mockEnvWithKeys);
|
|
117
|
+
const result = resolveRuntimeFromPdConfig(tmp, { getEnvVar: mockEnvWithKeys });
|
|
118
118
|
expect(result.runtimeProfileId).toBe('pi-ai.test');
|
|
119
119
|
expect(result.runtimeProfileLabel).toBe('pi-ai: openrouter/anthropic/claude-sonnet-4');
|
|
120
120
|
} finally { rmTmpDir(tmp); }
|
|
@@ -141,7 +141,7 @@ describe('buildProfileLabel', () => {
|
|
|
141
141
|
},
|
|
142
142
|
}));
|
|
143
143
|
try {
|
|
144
|
-
const result = resolveRuntimeFromPdConfig(tmp, mockEnvWithKeys);
|
|
144
|
+
const result = resolveRuntimeFromPdConfig(tmp, { getEnvVar: mockEnvWithKeys });
|
|
145
145
|
expect(result.runtimeProfileId).toBe(null);
|
|
146
146
|
expect(result.runtimeProfileLabel).toBe(null);
|
|
147
147
|
} finally { rmTmpDir(tmp); }
|
|
@@ -218,7 +218,7 @@ describe('resolveRuntimeFromPdConfig', () => {
|
|
|
218
218
|
const tmp = mkTmpDir();
|
|
219
219
|
writeConfig(tmp, makeValidPiAiConfigYaml(tmp));
|
|
220
220
|
try {
|
|
221
|
-
const result = resolveRuntimeFromPdConfig(tmp, mockEnvWithKeys);
|
|
221
|
+
const result = resolveRuntimeFromPdConfig(tmp, { getEnvVar: mockEnvWithKeys });
|
|
222
222
|
expect(isRuntimeConfigError(result.result)).toBe(false);
|
|
223
223
|
expect(result.configSource).toBe('.pd/config.yaml');
|
|
224
224
|
} finally { rmTmpDir(tmp); }
|