@principles/pd-cli 1.152.11 → 1.152.13
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/candidate.d.ts +3 -3
- package/dist/commands/candidate.d.ts.map +1 -1
- package/dist/commands/candidate.js +9 -21
- package/dist/commands/candidate.js.map +1 -1
- package/dist/index.js +0 -0
- package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
- package/dist/services/rulehost-pipeline-runner.js +4 -17
- package/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/package.json +13 -7
- package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
- package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
- package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
- package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
- package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
- package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
- package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
- package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
- package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
- package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
- package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
- package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
- package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
- package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
- package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
- package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
- package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
- package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
- package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
- package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
- package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
- package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
- package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/version.test.d.ts +0 -2
- package/dist/commands/__tests__/version.test.d.ts.map +0 -1
- package/dist/commands/__tests__/version.test.js +0 -238
- package/dist/commands/__tests__/version.test.js.map +0 -1
- package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
- package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
- package/dist/commands/runtime-uat.guard.test.js +0 -153
- package/dist/commands/runtime-uat.guard.test.js.map +0 -1
- package/dist/services/__tests__/cli-output.test.d.ts +0 -18
- package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
- package/dist/services/__tests__/cli-output.test.js +0 -103
- package/dist/services/__tests__/cli-output.test.js.map +0 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
- package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
- package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
- package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
- package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
- package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
- package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
- package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
- package/dist/utils/production-workspace-guard.test.d.ts +0 -2
- package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
- package/dist/utils/production-workspace-guard.test.js +0 -137
- package/dist/utils/production-workspace-guard.test.js.map +0 -1
- package/scripts/llm-dogfood.ts +0 -456
- package/scripts/migrate-illegal-expected-decision.ts +0 -252
- package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
- package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
- package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
- package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
- package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
- package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
- package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
- package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
- package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
- package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
- package/src/commands/__tests__/version.test.ts +0 -251
- package/src/commands/admission-gate.ts +0 -30
- package/src/commands/artifact.ts +0 -82
- package/src/commands/build-trajectory-evidence.ts +0 -298
- package/src/commands/candidate.ts +0 -1260
- package/src/commands/codex-ingest-catchup.ts +0 -114
- package/src/commands/codex-ingest-quarantine.ts +0 -127
- package/src/commands/codex-reconcile.ts +0 -84
- package/src/commands/codex-setup.ts +0 -476
- package/src/commands/codex-worker.ts +0 -185
- package/src/commands/command-helpers.ts +0 -24
- package/src/commands/config-doctor.ts +0 -193
- package/src/commands/console.ts +0 -797
- package/src/commands/context.ts +0 -72
- package/src/commands/demo-story-a.ts +0 -241
- package/src/commands/diagnose.ts +0 -756
- package/src/commands/errors-list.ts +0 -441
- package/src/commands/evolution-tasks-list.ts +0 -48
- package/src/commands/evolution-tasks-show.ts +0 -62
- package/src/commands/flow.ts +0 -60
- package/src/commands/health-codex.ts +0 -576
- package/src/commands/health.ts +0 -315
- package/src/commands/history.ts +0 -63
- package/src/commands/intent.ts +0 -457
- package/src/commands/legacy-cleanup.ts +0 -531
- package/src/commands/legacy-import.ts +0 -104
- package/src/commands/mvp-smoke.ts +0 -160
- package/src/commands/pain-evidence.ts +0 -226
- package/src/commands/pain-list.ts +0 -239
- package/src/commands/pain-record.ts +0 -612
- package/src/commands/pain-retry.ts +0 -916
- package/src/commands/principles-stats.ts +0 -700
- package/src/commands/proven-channel-baseline.ts +0 -115
- package/src/commands/quality-scorecard.ts +0 -272
- package/src/commands/remediation-output.ts +0 -66
- package/src/commands/rulecode.ts +0 -465
- package/src/commands/run.ts +0 -89
- package/src/commands/runtime-activation.ts +0 -1629
- package/src/commands/runtime-artifact-repair.ts +0 -524
- package/src/commands/runtime-canary.ts +0 -395
- package/src/commands/runtime-compatibility-scan.ts +0 -105
- package/src/commands/runtime-diagnostics-export.ts +0 -229
- package/src/commands/runtime-features.ts +0 -153
- package/src/commands/runtime-gfi-snapshot.ts +0 -135
- package/src/commands/runtime-health-snapshot.ts +0 -108
- package/src/commands/runtime-init.ts +0 -429
- package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
- package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
- package/src/commands/runtime-internalization-integrity.ts +0 -107
- package/src/commands/runtime-internalization-queue.ts +0 -135
- package/src/commands/runtime-internalization-retry.ts +0 -191
- package/src/commands/runtime-internalization-run-once.ts +0 -791
- package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
- package/src/commands/runtime-internalization-wake-once.ts +0 -87
- package/src/commands/runtime-pain-flood-simulation.ts +0 -121
- package/src/commands/runtime-pruning.ts +0 -438
- package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
- package/src/commands/runtime-recovery.ts +0 -109
- package/src/commands/runtime-synthetic-baseline.ts +0 -70
- package/src/commands/runtime-uat.guard.test.ts +0 -175
- package/src/commands/runtime-uat.ts +0 -380
- package/src/commands/runtime.ts +0 -473
- package/src/commands/samples-list.ts +0 -39
- package/src/commands/samples-review.ts +0 -36
- package/src/commands/task.ts +0 -271
- package/src/commands/telemetry.ts +0 -349
- package/src/commands/trace.ts +0 -174
- package/src/commands/trajectory-db-unavailable.ts +0 -19
- package/src/commands/trajectory.ts +0 -64
- package/src/commands/version.ts +0 -49
- package/src/config-reader.ts +0 -122
- package/src/index.ts +0 -1276
- package/src/legacy/legacy-import.ts +0 -179
- package/src/legacy/session-history-import.ts +0 -203
- package/src/resolve-workspace.ts +0 -106
- package/src/services/__tests__/cli-output.test.ts +0 -130
- package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
- package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
- package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
- package/src/services/cli-output.ts +0 -95
- package/src/services/config-doctor.ts +0 -697
- package/src/services/console-launcher.ts +0 -537
- package/src/services/demo-rule-compiler.ts +0 -40
- package/src/services/demo-story-a-runner.ts +0 -471
- package/src/services/mainline-snapshot-assembler.ts +0 -579
- package/src/services/pain-flood-simulation-runner.ts +0 -462
- package/src/services/pd-config-loader.ts +0 -433
- package/src/services/proven-channel-baseline-runner.ts +0 -157
- package/src/services/quality-scorecard/data-extractor.ts +0 -150
- package/src/services/quality-scorecard/local-evaluator.ts +0 -142
- package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
- package/src/services/resolve-runtime-from-pd-config.ts +0 -230
- package/src/services/rulehost-pipeline-runner.ts +0 -1216
- package/src/services/rulehost-readiness.ts +0 -326
- package/src/services/runtime-adapter-resolver.ts +0 -364
- package/src/services/synthetic-baseline-runner.ts +0 -400
- package/src/services/version-report.ts +0 -253
- package/src/services/workspace-tool-semantics.ts +0 -26
- package/src/utils/path-security.ts +0 -96
- package/src/utils/production-workspace-guard.test.ts +0 -157
- package/src/utils/production-workspace-guard.ts +0 -210
- package/tests/bdd/cli-contract.steps.ts +0 -346
- package/tests/bdd/principles-stats.steps.ts +0 -211
- package/tests/bdd/support/gherkin-loader.ts +0 -147
- package/tests/bdd/support/repo-root.ts +0 -62
- package/tests/bdd/support/vitest-bdd.ts +0 -179
- package/tests/commands/admission-gate-coverage.test.ts +0 -79
- package/tests/commands/build-trajectory-evidence.test.ts +0 -508
- package/tests/commands/candidate-audit-repair.test.ts +0 -421
- package/tests/commands/candidate-intake.test.ts +0 -732
- package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
- package/tests/commands/candidate-internalize-lineage.test.ts +0 -565
- package/tests/commands/candidate-internalize.test.ts +0 -299
- package/tests/commands/candidate-route.test.ts +0 -329
- package/tests/commands/candidate-show.test.ts +0 -95
- package/tests/commands/cli-command-tree.test.ts +0 -144
- package/tests/commands/cli-help-snapshot.test.ts +0 -155
- package/tests/commands/cli-skill-contract.test.ts +0 -121
- package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
- package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
- package/tests/commands/codex-setup.test.ts +0 -297
- package/tests/commands/codex-worker-daemon.test.ts +0 -95
- package/tests/commands/codex-worker-registration.test.ts +0 -207
- package/tests/commands/config-doctor.test.ts +0 -336
- package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
- package/tests/commands/console-open.test.ts +0 -1381
- package/tests/commands/context.test.ts +0 -114
- package/tests/commands/demo-story-a.test.ts +0 -318
- package/tests/commands/diagnose.test.ts +0 -1803
- package/tests/commands/errors-list.test.ts +0 -679
- package/tests/commands/evolution-tasks-list.test.ts +0 -41
- package/tests/commands/evolution-tasks-show.test.ts +0 -46
- package/tests/commands/health-codex.test.ts +0 -349
- package/tests/commands/health-host-wiring.test.ts +0 -76
- package/tests/commands/health-reliability.test.ts +0 -99
- package/tests/commands/health.test.ts +0 -413
- package/tests/commands/intent.test.ts +0 -321
- package/tests/commands/legacy-cleanup.test.ts +0 -148
- package/tests/commands/pain-evidence.test.ts +0 -518
- package/tests/commands/pain-list.test.ts +0 -219
- package/tests/commands/pain-record-async.test.ts +0 -335
- package/tests/commands/pain-record-session-parser.test.ts +0 -228
- package/tests/commands/pain-record.test.ts +0 -851
- package/tests/commands/pain-retry.test.ts +0 -1121
- package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
- package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
- package/tests/commands/principles-stats-wiring.test.ts +0 -135
- package/tests/commands/principles-stats.test.ts +0 -274
- package/tests/commands/product-path-regression.test.ts +0 -86
- package/tests/commands/proven-channel-baseline.test.ts +0 -441
- package/tests/commands/rulecode.test.ts +0 -177
- package/tests/commands/run-rulehost-handler.test.ts +0 -908
- package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
- package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
- package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
- package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
- package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
- package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
- package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
- package/tests/commands/runtime-activation.test.ts +0 -2052
- package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
- package/tests/commands/runtime-artifact-repair.test.ts +0 -404
- package/tests/commands/runtime-canary.test.ts +0 -430
- package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
- package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
- package/tests/commands/runtime-features.test.ts +0 -249
- package/tests/commands/runtime-health-snapshot.test.ts +0 -358
- package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
- package/tests/commands/runtime-init.test.ts +0 -420
- package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
- package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
- package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
- package/tests/commands/runtime-internalization-queue.test.ts +0 -380
- package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
- package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
- package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
- package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
- package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
- package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
- package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
- package/tests/commands/runtime-internalization.test.ts +0 -53
- package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
- package/tests/commands/runtime-pruning.test.ts +0 -694
- package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
- package/tests/commands/runtime-recovery.test.ts +0 -120
- package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
- package/tests/commands/runtime-uat.test.ts +0 -397
- package/tests/commands/runtime.test.ts +0 -392
- package/tests/commands/samples-list.test.ts +0 -43
- package/tests/commands/samples-review.test.ts +0 -41
- package/tests/commands/task.test.ts +0 -153
- package/tests/commands/telemetry.test.ts +0 -190
- package/tests/commands/trace.test.ts +0 -316
- package/tests/config-reader.test.ts +0 -143
- package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
- package/tests/e2e/cli-full-flow.test.ts +0 -233
- package/tests/e2e/cross-package-acceptance.test.ts +0 -635
- package/tests/helpers/pd-cli-path.ts +0 -5
- package/tests/pd-cli-smoke.test.ts +0 -13
- package/tests/resolve-workspace.test.ts +0 -196
- package/tests/services/config-doctor-signal-health.test.ts +0 -109
- package/tests/services/console-launcher.test.ts +0 -114
- package/tests/services/demo-rule-compiler.test.ts +0 -242
- package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
- package/tests/services/pd-config-loader.test.ts +0 -505
- package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
- package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
- package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
- package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
- package/tests/services/rulehost-pipeline-runner.test.ts +0 -1175
- package/tests/services/workspace-tool-semantics.test.ts +0 -76
- package/tests/utils/path-security.test.ts +0 -180
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -9
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
|
|
4
|
-
const { mockClose, mockDeactivate, mockWriteGovernanceAction } = vi.hoisted(() => ({
|
|
5
|
-
mockClose: vi.fn().mockResolvedValue(undefined),
|
|
6
|
-
mockDeactivate: vi.fn().mockResolvedValue(true),
|
|
7
|
-
mockWriteGovernanceAction: vi.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
11
|
-
resolveWorkspaceDir: vi.fn(() => '/workspace'),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
vi.mock('principles-disciple/governance-audit', () => ({
|
|
15
|
-
writeGovernanceAction: mockWriteGovernanceAction,
|
|
16
|
-
authorizeGovernanceAction: vi.fn(async (_stateDir, _data, mutation) => mutation()),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
vi.mock('@principles/core/runtime-v2', async (importOriginal) => {
|
|
20
|
-
const original = await importOriginal() as Record<string, unknown>;
|
|
21
|
-
return {
|
|
22
|
-
...original,
|
|
23
|
-
RuntimeStateManager: vi.fn().mockImplementation(function () {
|
|
24
|
-
return {
|
|
25
|
-
initialize: vi.fn().mockResolvedValue(undefined),
|
|
26
|
-
close: mockClose,
|
|
27
|
-
connection: {},
|
|
28
|
-
};
|
|
29
|
-
}),
|
|
30
|
-
SqliteActivationStateStore: vi.fn().mockImplementation(function () {
|
|
31
|
-
return { deactivateActivation: mockDeactivate };
|
|
32
|
-
}),
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
import { handleRuntimeActivationDeactivate } from '../../src/commands/runtime-activation.js';
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
vi.clearAllMocks();
|
|
40
|
-
mockDeactivate.mockResolvedValue(true);
|
|
41
|
-
process.exitCode = 0;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterEach(() => {
|
|
45
|
-
process.exitCode = 0;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('deactivate governance audit ordering (PRI-566)', () => {
|
|
49
|
-
it('durably authorizes the canonical audit event before mutating activation state', async () => {
|
|
50
|
-
const callOrder: string[] = [];
|
|
51
|
-
mockWriteGovernanceAction.mockImplementation(() => { callOrder.push('audit'); });
|
|
52
|
-
mockDeactivate.mockImplementation(async () => { callOrder.push('mutation'); return true; });
|
|
53
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
54
|
-
|
|
55
|
-
await handleRuntimeActivationDeactivate({
|
|
56
|
-
workspace: '/workspace',
|
|
57
|
-
activationId: 'act-566',
|
|
58
|
-
reasonCode: 'owner_requested_rollback',
|
|
59
|
-
json: true,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
expect(callOrder).toEqual(['audit', 'mutation']);
|
|
63
|
-
expect(mockWriteGovernanceAction).toHaveBeenCalledWith(path.join(path.resolve('/workspace'), '.pd'), {
|
|
64
|
-
action: 'deactivate',
|
|
65
|
-
activationId: 'act-566',
|
|
66
|
-
actor: 'cli',
|
|
67
|
-
reasonCode: 'owner_requested_rollback',
|
|
68
|
-
outcome: 'authorized',
|
|
69
|
-
});
|
|
70
|
-
expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject({ ok: true, activationId: 'act-566' });
|
|
71
|
-
logSpy.mockRestore();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('refuses without mutation when the audit event cannot be persisted', async () => {
|
|
75
|
-
mockWriteGovernanceAction.mockImplementation(() => { throw new Error('disk full'); });
|
|
76
|
-
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
77
|
-
|
|
78
|
-
await handleRuntimeActivationDeactivate({
|
|
79
|
-
workspace: '/workspace',
|
|
80
|
-
activationId: 'act-566',
|
|
81
|
-
reasonCode: 'owner_requested_rollback',
|
|
82
|
-
json: true,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
expect(mockDeactivate).not.toHaveBeenCalled();
|
|
86
|
-
expect(process.exitCode).toBe(1);
|
|
87
|
-
expect(logSpy).toHaveBeenCalledTimes(1);
|
|
88
|
-
expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject({
|
|
89
|
-
ok: false,
|
|
90
|
-
reason: 'governance_audit_failed: disk full',
|
|
91
|
-
nextAction: expect.stringMatching(/retry/i),
|
|
92
|
-
});
|
|
93
|
-
logSpy.mockRestore();
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parser-level tests for `pd activation list` flags (CLI gate rule 7).
|
|
3
|
-
*
|
|
4
|
-
* Mirrors `runtime-activation-promote-flag-wiring.test.ts`. Exercises the real
|
|
5
|
-
* `registerRuntimeActivationListCommand` helper (single source of truth
|
|
6
|
-
* shared with `index.ts`). Flag typos in production surface here at
|
|
7
|
-
* parseAsync time, not at handler dispatch.
|
|
8
|
-
*
|
|
9
|
-
* Covers:
|
|
10
|
-
* - --json is registered
|
|
11
|
-
* - --workspace / -w and --channel / -c shorthand flags are registered
|
|
12
|
-
* - --include-deactivated is registered
|
|
13
|
-
* - --dry-run / --confirm / --no-json are NOT registered
|
|
14
|
-
*
|
|
15
|
-
* Handler-level behavior (filtering, JSON output shape) is covered by
|
|
16
|
-
* runtime-activation.test.ts.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { describe, it, expect } from 'vitest';
|
|
20
|
-
import { Command } from 'commander';
|
|
21
|
-
|
|
22
|
-
import { registerRuntimeActivationListCommand } from '../../src/commands/runtime-activation.js';
|
|
23
|
-
|
|
24
|
-
type ActionOptions = Record<string, unknown>;
|
|
25
|
-
|
|
26
|
-
interface CapturedAction {
|
|
27
|
-
opts: ActionOptions | null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function attachCapture(cmd: Command, state: CapturedAction): void {
|
|
31
|
-
cmd.action(function captureAction(...args: unknown[]): void {
|
|
32
|
-
let optsArg: unknown = null;
|
|
33
|
-
for (let i = args.length - 1; i >= 0; i--) {
|
|
34
|
-
const arg: unknown = args[i];
|
|
35
|
-
if (arg !== null && typeof arg === 'object' && !(arg instanceof Command)) {
|
|
36
|
-
optsArg = arg;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (optsArg !== null && typeof optsArg === 'object') {
|
|
41
|
-
state.opts = optsArg as ActionOptions;
|
|
42
|
-
} else {
|
|
43
|
-
state.opts = {};
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function freshProgram(): Command {
|
|
49
|
-
const program = new Command();
|
|
50
|
-
program.name('pd').exitOverride();
|
|
51
|
-
return program;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
describe('pd activation list — flag wiring (CLI gate rule 7)', () => {
|
|
55
|
-
// ── Option metadata ──────────────────────────────────────────────────────
|
|
56
|
-
|
|
57
|
-
it('registers --json flag', () => {
|
|
58
|
-
const program = freshProgram();
|
|
59
|
-
const activationCmd = program.command('activation');
|
|
60
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
61
|
-
|
|
62
|
-
const opt = listCmd.options.find((o) => o.long === '--json');
|
|
63
|
-
expect(opt).toBeDefined();
|
|
64
|
-
expect(opt?.long).toBe('--json');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('registers -w shorthand for --workspace', () => {
|
|
68
|
-
const program = freshProgram();
|
|
69
|
-
const activationCmd = program.command('activation');
|
|
70
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
71
|
-
|
|
72
|
-
const opt = listCmd.options.find((o) => o.short === '-w');
|
|
73
|
-
expect(opt).toBeDefined();
|
|
74
|
-
expect(opt?.long).toBe('--workspace');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('registers -c shorthand for --channel', () => {
|
|
78
|
-
const program = freshProgram();
|
|
79
|
-
const activationCmd = program.command('activation');
|
|
80
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
81
|
-
|
|
82
|
-
const opt = listCmd.options.find((o) => o.short === '-c');
|
|
83
|
-
expect(opt).toBeDefined();
|
|
84
|
-
expect(opt?.long).toBe('--channel');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('registers --include-deactivated', () => {
|
|
88
|
-
const program = freshProgram();
|
|
89
|
-
const activationCmd = program.command('activation');
|
|
90
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
91
|
-
|
|
92
|
-
const opt = listCmd.options.find((o) => o.long === '--include-deactivated');
|
|
93
|
-
expect(opt).toBeDefined();
|
|
94
|
-
expect(opt?.long).toBe('--include-deactivated');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('does NOT register --dry-run', () => {
|
|
98
|
-
const program = freshProgram();
|
|
99
|
-
const activationCmd = program.command('activation');
|
|
100
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
101
|
-
|
|
102
|
-
const opt = listCmd.options.find((o) => o.long === '--dry-run');
|
|
103
|
-
expect(opt).toBeUndefined();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('does NOT register --confirm', () => {
|
|
107
|
-
const program = freshProgram();
|
|
108
|
-
const activationCmd = program.command('activation');
|
|
109
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
110
|
-
|
|
111
|
-
const opt = listCmd.options.find((o) => o.long === '--confirm');
|
|
112
|
-
expect(opt).toBeUndefined();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('does NOT register --no-json (no accidental negation)', () => {
|
|
116
|
-
const program = freshProgram();
|
|
117
|
-
const activationCmd = program.command('activation');
|
|
118
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
119
|
-
|
|
120
|
-
const noForm = listCmd.options.find((o) => o.long === '--no-json');
|
|
121
|
-
expect(noForm).toBeUndefined();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// ── Parser-level tests (program.parseAsync) ───────────────────────────────
|
|
125
|
-
|
|
126
|
-
it('parses --json as true', async () => {
|
|
127
|
-
const program = freshProgram();
|
|
128
|
-
const activationCmd = program.command('activation');
|
|
129
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
130
|
-
const captured: CapturedAction = { opts: null };
|
|
131
|
-
attachCapture(listCmd, captured);
|
|
132
|
-
|
|
133
|
-
await program.parseAsync(['node', 'pd', 'activation', 'list', '--json']);
|
|
134
|
-
|
|
135
|
-
expect(captured.opts).not.toBeNull();
|
|
136
|
-
expect(captured.opts?.json).toBe(true);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('parses -w shorthand for --workspace', async () => {
|
|
140
|
-
const program = freshProgram();
|
|
141
|
-
const activationCmd = program.command('activation');
|
|
142
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
143
|
-
const captured: CapturedAction = { opts: null };
|
|
144
|
-
attachCapture(listCmd, captured);
|
|
145
|
-
|
|
146
|
-
await program.parseAsync(['node', 'pd', 'activation', 'list', '-w', '/tmp/test']);
|
|
147
|
-
|
|
148
|
-
expect(captured.opts).not.toBeNull();
|
|
149
|
-
expect(captured.opts?.workspace).toBe('/tmp/test');
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('parses -c shorthand for --channel', async () => {
|
|
153
|
-
const program = freshProgram();
|
|
154
|
-
const activationCmd = program.command('activation');
|
|
155
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
156
|
-
const captured: CapturedAction = { opts: null };
|
|
157
|
-
attachCapture(listCmd, captured);
|
|
158
|
-
|
|
159
|
-
await program.parseAsync(['node', 'pd', 'activation', 'list', '-c', 'prompt']);
|
|
160
|
-
|
|
161
|
-
expect(captured.opts).not.toBeNull();
|
|
162
|
-
expect(captured.opts?.channel).toBe('prompt');
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('parses --include-deactivated as true', async () => {
|
|
166
|
-
const program = freshProgram();
|
|
167
|
-
const activationCmd = program.command('activation');
|
|
168
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
169
|
-
const captured: CapturedAction = { opts: null };
|
|
170
|
-
attachCapture(listCmd, captured);
|
|
171
|
-
|
|
172
|
-
await program.parseAsync(['node', 'pd', 'activation', 'list', '--include-deactivated']);
|
|
173
|
-
|
|
174
|
-
expect(captured.opts).not.toBeNull();
|
|
175
|
-
expect(captured.opts?.includeDeactivated).toBe(true);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('defaults all flags to undefined when none passed', async () => {
|
|
179
|
-
const program = freshProgram();
|
|
180
|
-
const activationCmd = program.command('activation');
|
|
181
|
-
const listCmd = registerRuntimeActivationListCommand(activationCmd);
|
|
182
|
-
const captured: CapturedAction = { opts: null };
|
|
183
|
-
attachCapture(listCmd, captured);
|
|
184
|
-
|
|
185
|
-
await program.parseAsync(['node', 'pd', 'activation', 'list']);
|
|
186
|
-
|
|
187
|
-
expect(captured.opts).not.toBeNull();
|
|
188
|
-
expect(captured.opts?.json).toBeUndefined();
|
|
189
|
-
expect(captured.opts?.workspace).toBeUndefined();
|
|
190
|
-
expect(captured.opts?.channel).toBeUndefined();
|
|
191
|
-
expect(captured.opts?.includeDeactivated).toBeUndefined();
|
|
192
|
-
});
|
|
193
|
-
});
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parser-level tests for `pd activation promote` flags (CLI gate rule 7).
|
|
3
|
-
*
|
|
4
|
-
* Mirrors `run-rulehost-flag-wiring.test.ts`. Exercises the real
|
|
5
|
-
* `registerRuntimeActivationPromoteCommand` helper (single source of truth
|
|
6
|
-
* shared with `index.ts`). Flag typos in production surface here at
|
|
7
|
-
* parseAsync time, not at handler dispatch.
|
|
8
|
-
*
|
|
9
|
-
* Covers:
|
|
10
|
-
* - --dry-run and --confirm are registered
|
|
11
|
-
* - --json is registered
|
|
12
|
-
* - --activation-id is required (Commander rejects missing required option)
|
|
13
|
-
* - --workspace / -w shorthand is registered
|
|
14
|
-
* - --no-dry-run / --no-confirm are NOT registered (no accidental negation)
|
|
15
|
-
*
|
|
16
|
-
* Handler-level behavior (mutual exclusivity enforcement, JSON output shape,
|
|
17
|
-
* refusal reasons) is covered by runtime-activation.test.ts.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import { describe, it, expect } from 'vitest';
|
|
21
|
-
import { Command } from 'commander';
|
|
22
|
-
|
|
23
|
-
import { registerRuntimeActivationPromoteCommand } from '../../src/commands/runtime-activation.js';
|
|
24
|
-
|
|
25
|
-
type ActionOptions = Record<string, unknown>;
|
|
26
|
-
|
|
27
|
-
interface CapturedAction {
|
|
28
|
-
opts: ActionOptions | null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function attachCapture(cmd: Command, state: CapturedAction): void {
|
|
32
|
-
cmd.action(function captureAction(...args: unknown[]): void {
|
|
33
|
-
let optsArg: unknown = null;
|
|
34
|
-
for (let i = args.length - 1; i >= 0; i--) {
|
|
35
|
-
const arg: unknown = args[i];
|
|
36
|
-
if (arg !== null && typeof arg === 'object' && !(arg instanceof Command)) {
|
|
37
|
-
optsArg = arg;
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (optsArg !== null && typeof optsArg === 'object') {
|
|
42
|
-
state.opts = optsArg as ActionOptions;
|
|
43
|
-
} else {
|
|
44
|
-
state.opts = {};
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function freshProgram(): Command {
|
|
50
|
-
const program = new Command();
|
|
51
|
-
program.name('pd').exitOverride();
|
|
52
|
-
return program;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
describe('pd activation promote — flag wiring (CLI gate rule 7)', () => {
|
|
56
|
-
// ── Option metadata ──────────────────────────────────────────────────────
|
|
57
|
-
|
|
58
|
-
it('registers --dry-run flag', () => {
|
|
59
|
-
const program = freshProgram();
|
|
60
|
-
const activationCmd = program.command('activation');
|
|
61
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
62
|
-
|
|
63
|
-
const opt = promoteCmd.options.find((o) => o.long === '--dry-run');
|
|
64
|
-
expect(opt).toBeDefined();
|
|
65
|
-
expect(opt?.long).toBe('--dry-run');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('registers --confirm flag', () => {
|
|
69
|
-
const program = freshProgram();
|
|
70
|
-
const activationCmd = program.command('activation');
|
|
71
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
72
|
-
|
|
73
|
-
const opt = promoteCmd.options.find((o) => o.long === '--confirm');
|
|
74
|
-
expect(opt).toBeDefined();
|
|
75
|
-
expect(opt?.long).toBe('--confirm');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('registers --json flag', () => {
|
|
79
|
-
const program = freshProgram();
|
|
80
|
-
const activationCmd = program.command('activation');
|
|
81
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
82
|
-
|
|
83
|
-
const opt = promoteCmd.options.find((o) => o.long === '--json');
|
|
84
|
-
expect(opt).toBeDefined();
|
|
85
|
-
expect(opt?.long).toBe('--json');
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it.each(['--artifact-id', '--artifact-digest', '--control-version', '--idempotency-key', '--reason', '--note'])(
|
|
89
|
-
'registers Owner authority binding option %s', (flag) => {
|
|
90
|
-
const program = freshProgram();
|
|
91
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(program.command('activation'));
|
|
92
|
-
expect(promoteCmd.options.find(option => option.long === flag)).toBeDefined();
|
|
93
|
-
},
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
it('registers --activation-id as required option', () => {
|
|
97
|
-
const program = freshProgram();
|
|
98
|
-
const activationCmd = program.command('activation');
|
|
99
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
100
|
-
|
|
101
|
-
const opt = promoteCmd.options.find((o) => o.long === '--activation-id');
|
|
102
|
-
expect(opt).toBeDefined();
|
|
103
|
-
expect(opt?.long).toBe('--activation-id');
|
|
104
|
-
expect(opt?.required).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('registers -w shorthand for --workspace', () => {
|
|
108
|
-
const program = freshProgram();
|
|
109
|
-
const activationCmd = program.command('activation');
|
|
110
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
111
|
-
|
|
112
|
-
const opt = promoteCmd.options.find((o) => o.short === '-w');
|
|
113
|
-
expect(opt).toBeDefined();
|
|
114
|
-
expect(opt?.long).toBe('--workspace');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('does NOT register --no-dry-run (no accidental negation)', () => {
|
|
118
|
-
const program = freshProgram();
|
|
119
|
-
const activationCmd = program.command('activation');
|
|
120
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
121
|
-
|
|
122
|
-
const noForm = promoteCmd.options.find((o) => o.long === '--no-dry-run');
|
|
123
|
-
expect(noForm).toBeUndefined();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('does NOT register --no-confirm (no accidental negation)', () => {
|
|
127
|
-
const program = freshProgram();
|
|
128
|
-
const activationCmd = program.command('activation');
|
|
129
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
130
|
-
|
|
131
|
-
const noForm = promoteCmd.options.find((o) => o.long === '--no-confirm');
|
|
132
|
-
expect(noForm).toBeUndefined();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// ── Parser-level tests (program.parseAsync) ───────────────────────────────
|
|
136
|
-
|
|
137
|
-
it('parses --dry-run as true', async () => {
|
|
138
|
-
const program = freshProgram();
|
|
139
|
-
const activationCmd = program.command('activation');
|
|
140
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
141
|
-
const captured: CapturedAction = { opts: null };
|
|
142
|
-
attachCapture(promoteCmd, captured);
|
|
143
|
-
|
|
144
|
-
await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '--dry-run']);
|
|
145
|
-
|
|
146
|
-
expect(captured.opts).not.toBeNull();
|
|
147
|
-
expect(captured.opts?.dryRun).toBe(true);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('parses --confirm as true', async () => {
|
|
151
|
-
const program = freshProgram();
|
|
152
|
-
const activationCmd = program.command('activation');
|
|
153
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
154
|
-
const captured: CapturedAction = { opts: null };
|
|
155
|
-
attachCapture(promoteCmd, captured);
|
|
156
|
-
|
|
157
|
-
await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '--confirm']);
|
|
158
|
-
|
|
159
|
-
expect(captured.opts).not.toBeNull();
|
|
160
|
-
expect(captured.opts?.confirm).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('parses both --dry-run and --confirm (handler enforces mutual exclusivity)', async () => {
|
|
164
|
-
// Commander parses both flags; the handler validates mutual exclusivity.
|
|
165
|
-
// This test proves the parser accepts both — the handler test in
|
|
166
|
-
// runtime-activation.test.ts proves the handler rejects the combination.
|
|
167
|
-
const program = freshProgram();
|
|
168
|
-
const activationCmd = program.command('activation');
|
|
169
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
170
|
-
const captured: CapturedAction = { opts: null };
|
|
171
|
-
attachCapture(promoteCmd, captured);
|
|
172
|
-
|
|
173
|
-
await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '--dry-run', '--confirm']);
|
|
174
|
-
|
|
175
|
-
expect(captured.opts).not.toBeNull();
|
|
176
|
-
expect(captured.opts?.dryRun).toBe(true);
|
|
177
|
-
expect(captured.opts?.confirm).toBe(true);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('defaults --dry-run and --confirm to undefined when neither is passed', async () => {
|
|
181
|
-
const program = freshProgram();
|
|
182
|
-
const activationCmd = program.command('activation');
|
|
183
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
184
|
-
const captured: CapturedAction = { opts: null };
|
|
185
|
-
attachCapture(promoteCmd, captured);
|
|
186
|
-
|
|
187
|
-
await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1']);
|
|
188
|
-
|
|
189
|
-
expect(captured.opts).not.toBeNull();
|
|
190
|
-
expect(captured.opts?.dryRun).toBeUndefined();
|
|
191
|
-
expect(captured.opts?.confirm).toBeUndefined();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('parses --json as true', async () => {
|
|
195
|
-
const program = freshProgram();
|
|
196
|
-
const activationCmd = program.command('activation');
|
|
197
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
198
|
-
const captured: CapturedAction = { opts: null };
|
|
199
|
-
attachCapture(promoteCmd, captured);
|
|
200
|
-
|
|
201
|
-
await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '--json']);
|
|
202
|
-
|
|
203
|
-
expect(captured.opts).not.toBeNull();
|
|
204
|
-
expect(captured.opts?.json).toBe(true);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it('parses -w shorthand for --workspace', async () => {
|
|
208
|
-
const program = freshProgram();
|
|
209
|
-
const activationCmd = program.command('activation');
|
|
210
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(activationCmd);
|
|
211
|
-
const captured: CapturedAction = { opts: null };
|
|
212
|
-
attachCapture(promoteCmd, captured);
|
|
213
|
-
|
|
214
|
-
await program.parseAsync(['node', 'pd', 'activation', 'promote', '--activation-id', 'act-1', '-w', '/tmp/test']);
|
|
215
|
-
|
|
216
|
-
expect(captured.opts).not.toBeNull();
|
|
217
|
-
expect(captured.opts?.workspace).toBe('/tmp/test');
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('parses all Owner authority binding values through the real command', async () => {
|
|
221
|
-
const program = freshProgram();
|
|
222
|
-
const promoteCmd = registerRuntimeActivationPromoteCommand(program.command('activation'));
|
|
223
|
-
const captured: CapturedAction = { opts: null };
|
|
224
|
-
attachCapture(promoteCmd, captured);
|
|
225
|
-
|
|
226
|
-
await program.parseAsync([
|
|
227
|
-
'node', 'pd', 'activation', 'promote', '--activation-id', 'act-1',
|
|
228
|
-
'--artifact-id', 'art-1', '--artifact-digest', 'sha256:one', '--control-version', '7',
|
|
229
|
-
'--idempotency-key', 'idem-1', '--reason', 'owner_review', '--note', 'reviewed', '--confirm',
|
|
230
|
-
]);
|
|
231
|
-
|
|
232
|
-
expect(captured.opts).toMatchObject({
|
|
233
|
-
artifactId: 'art-1', artifactDigest: 'sha256:one', controlVersion: 7,
|
|
234
|
-
idempotencyKey: 'idem-1', reason: 'owner_review', note: 'reviewed', confirm: true,
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('rejects missing --activation-id (required option)', async () => {
|
|
239
|
-
const program = freshProgram();
|
|
240
|
-
const activationCmd = program.command('activation');
|
|
241
|
-
registerRuntimeActivationPromoteCommand(activationCmd);
|
|
242
|
-
|
|
243
|
-
// Commander should throw on missing required option
|
|
244
|
-
await expect(
|
|
245
|
-
program.parseAsync(['node', 'pd', 'activation', 'promote', '--dry-run']),
|
|
246
|
-
).rejects.toThrow(/activation-id/);
|
|
247
|
-
});
|
|
248
|
-
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import * as fs from 'node:fs';
|
|
3
|
-
import * as os from 'node:os';
|
|
4
|
-
import * as path from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
collectRuleCodeEventEntries,
|
|
7
|
-
readShadowSummaryForActivation,
|
|
8
|
-
} from '../../src/commands/runtime-activation.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* PRI-577 regression tests — RuleCode shadow telemetry directory mismatch.
|
|
12
|
-
*
|
|
13
|
-
* Production writes rulehost_evaluated events to `{workspace}/.state/logs/` via the
|
|
14
|
-
* v1 EventLog component, while the reader used to scan only `{workspace}/.pd/logs/`
|
|
15
|
-
* (a directory no production code ever creates). These tests pin the real-world
|
|
16
|
-
* directory layout so a future refactor cannot silently re-break the channel.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const ACTIVATION_ID = 'act_code_test-rule';
|
|
20
|
-
|
|
21
|
-
function makeEventLine(eventOverrides: Record<string, unknown> = {}, dataOverrides: Record<string, unknown> = {}): string {
|
|
22
|
-
return JSON.stringify({
|
|
23
|
-
ts: '2026-08-21T00:47:00.469Z',
|
|
24
|
-
type: 'rulehost_evaluated',
|
|
25
|
-
category: 'evaluated',
|
|
26
|
-
data: {
|
|
27
|
-
toolName: 'write_file',
|
|
28
|
-
filePath: '<redacted>',
|
|
29
|
-
matched: true,
|
|
30
|
-
decision: 'block',
|
|
31
|
-
ruleId: 'rule-1',
|
|
32
|
-
activationId: ACTIVATION_ID,
|
|
33
|
-
activationMode: 'shadow',
|
|
34
|
-
...dataOverrides,
|
|
35
|
-
},
|
|
36
|
-
...eventOverrides,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
describe('PRI-577 shadow telemetry dual-directory reading', () => {
|
|
41
|
-
let workspaceDir: string;
|
|
42
|
-
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
workspaceDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pri577-ws-'));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
fs.rmSync(workspaceDir, { recursive: true, force: true });
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
function writeEventsFile(relLogsDir: string, date: string, lines: string[]): void {
|
|
52
|
-
const dir = path.join(workspaceDir, ...relLogsDir.split('/'));
|
|
53
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
54
|
-
fs.writeFileSync(path.join(dir, `events_${date}.jsonl`), lines.join('\n') + '\n', 'utf8');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
it('reads shadow metrics when events live only in legacy .state/logs (production layout)', () => {
|
|
58
|
-
writeEventsFile('.state/logs', '2026-08-21', [
|
|
59
|
-
makeEventLine(),
|
|
60
|
-
makeEventLine({}, { toolName: 'exec', filePath: 'x', matched: false, decision: 'allow' }),
|
|
61
|
-
]);
|
|
62
|
-
|
|
63
|
-
const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
|
|
64
|
-
expect(summary.observed).toBe(2);
|
|
65
|
-
expect(summary.matched).toBe(1);
|
|
66
|
-
expect(summary.wouldBlock).toBe(1);
|
|
67
|
-
expect(summary.firstObservedAt).not.toBeNull();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('merges entries when both .pd/logs and .state/logs exist', () => {
|
|
71
|
-
writeEventsFile('.state/logs', '2026-08-21', [makeEventLine()]);
|
|
72
|
-
writeEventsFile('.pd/logs', '2026-08-22', [
|
|
73
|
-
makeEventLine({ ts: '2026-08-22T10:00:00.000Z' }),
|
|
74
|
-
]);
|
|
75
|
-
const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
|
|
76
|
-
expect(summary.observed).toBe(2);
|
|
77
|
-
expect(summary.lastObservedAt).toBe('2026-08-22T10:00:00.000Z');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('keeps distinct events from same-named daily files and deduplicates exact copied lines', () => {
|
|
81
|
-
const copied = makeEventLine();
|
|
82
|
-
writeEventsFile('.state/logs', '2026-08-21', [
|
|
83
|
-
copied,
|
|
84
|
-
makeEventLine({}, { toolName: 'exec', filePath: 'x', matched: false, decision: 'allow' }),
|
|
85
|
-
]);
|
|
86
|
-
writeEventsFile('.pd/logs', '2026-08-21', [copied]);
|
|
87
|
-
|
|
88
|
-
const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
|
|
89
|
-
expect(summary.observed).toBe(2);
|
|
90
|
-
expect(summary.wouldAllow).toBe(1);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('reports zero (not unavailable) when a log dir exists but has no matching events', () => {
|
|
94
|
-
writeEventsFile('.state/logs', '2026-08-21', [
|
|
95
|
-
JSON.stringify({ ts: '2026-08-21T00:00:00.000Z', type: 'other_event', category: 'x', data: {} }),
|
|
96
|
-
]);
|
|
97
|
-
|
|
98
|
-
const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
|
|
99
|
-
// Distinguishes "channel alive, no data" (zeros) from "no channel" (nulls).
|
|
100
|
-
expect(summary.observed).toBe(0);
|
|
101
|
-
expect(summary.matched).toBe(0);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('returns unavailable summary only when neither candidate directory exists', () => {
|
|
105
|
-
const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
|
|
106
|
-
expect(summary).toEqual({
|
|
107
|
-
observed: null, matched: null, wouldBlock: null, wouldAllow: null,
|
|
108
|
-
requireApproval: null, autoCorrect: null, errors: null, neutralControl: null,
|
|
109
|
-
firstObservedAt: null, lastObservedAt: null,
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('does not report an unreadable candidate path as a healthy zero-event channel', () => {
|
|
114
|
-
fs.mkdirSync(path.join(workspaceDir, '.state'), { recursive: true });
|
|
115
|
-
fs.writeFileSync(path.join(workspaceDir, '.state', 'logs'), 'not a directory');
|
|
116
|
-
const summary = readShadowSummaryForActivation(workspaceDir, ACTIVATION_ID);
|
|
117
|
-
expect(summary.observed).toBeNull();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('excludes malformed telemetry lines instead of failing the whole scan', () => {
|
|
121
|
-
writeEventsFile('.state/logs', '2026-08-21', [
|
|
122
|
-
'{not-valid-json',
|
|
123
|
-
makeEventLine(),
|
|
124
|
-
]);
|
|
125
|
-
|
|
126
|
-
const collected = collectRuleCodeEventEntries(workspaceDir);
|
|
127
|
-
expect(collected.entries.length).toBe(1);
|
|
128
|
-
expect(collected.sourceDirsFound).toBeGreaterThanOrEqual(1);
|
|
129
|
-
});
|
|
130
|
-
});
|