@principles/pd-cli 1.133.0 → 1.134.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/__tests__/intent-flag-wiring.test.js +74 -3
- package/dist/commands/__tests__/intent-flag-wiring.test.js.map +1 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +2 -0
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +1 -0
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +60 -0
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +1 -0
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js +11 -4
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +1 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +9 -0
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +1 -1
- package/dist/commands/admission-gate.d.ts +24 -0
- package/dist/commands/admission-gate.d.ts.map +1 -0
- package/dist/commands/admission-gate.js +29 -0
- package/dist/commands/admission-gate.js.map +1 -0
- package/dist/commands/candidate.d.ts.map +1 -1
- package/dist/commands/candidate.js +72 -6
- package/dist/commands/candidate.js.map +1 -1
- package/dist/commands/console.d.ts.map +1 -1
- package/dist/commands/console.js +40 -0
- package/dist/commands/console.js.map +1 -1
- package/dist/commands/demo-story-a.d.ts.map +1 -1
- package/dist/commands/demo-story-a.js +4 -2
- package/dist/commands/demo-story-a.js.map +1 -1
- package/dist/commands/diagnose.d.ts.map +1 -1
- package/dist/commands/diagnose.js +155 -8
- package/dist/commands/diagnose.js.map +1 -1
- package/dist/commands/errors-list.d.ts +25 -0
- package/dist/commands/errors-list.d.ts.map +1 -0
- package/dist/commands/errors-list.js +368 -0
- package/dist/commands/errors-list.js.map +1 -0
- package/dist/commands/health-codex.d.ts +7 -0
- package/dist/commands/health-codex.d.ts.map +1 -0
- package/dist/commands/health-codex.js +209 -0
- package/dist/commands/health-codex.js.map +1 -0
- package/dist/commands/health.d.ts +24 -0
- package/dist/commands/health.d.ts.map +1 -1
- package/dist/commands/health.js +48 -0
- package/dist/commands/health.js.map +1 -1
- package/dist/commands/intent.d.ts +21 -4
- package/dist/commands/intent.d.ts.map +1 -1
- package/dist/commands/intent.js +88 -27
- package/dist/commands/intent.js.map +1 -1
- package/dist/commands/pain-evidence.d.ts +6 -0
- package/dist/commands/pain-evidence.d.ts.map +1 -1
- package/dist/commands/pain-evidence.js +6 -0
- package/dist/commands/pain-evidence.js.map +1 -1
- package/dist/commands/pain-record.d.ts.map +1 -1
- package/dist/commands/pain-record.js +21 -0
- package/dist/commands/pain-record.js.map +1 -1
- package/dist/commands/pain-retry.d.ts +4 -0
- package/dist/commands/pain-retry.d.ts.map +1 -1
- package/dist/commands/pain-retry.js +327 -32
- package/dist/commands/pain-retry.js.map +1 -1
- package/dist/commands/proven-channel-baseline.d.ts.map +1 -1
- package/dist/commands/proven-channel-baseline.js +4 -2
- package/dist/commands/proven-channel-baseline.js.map +1 -1
- package/dist/commands/runtime-activation.d.ts +30 -0
- package/dist/commands/runtime-activation.d.ts.map +1 -1
- package/dist/commands/runtime-activation.js +567 -11
- package/dist/commands/runtime-activation.js.map +1 -1
- package/dist/commands/runtime-canary.d.ts.map +1 -1
- package/dist/commands/runtime-canary.js +32 -7
- package/dist/commands/runtime-canary.js.map +1 -1
- package/dist/commands/runtime-health-snapshot.d.ts.map +1 -1
- package/dist/commands/runtime-health-snapshot.js +4 -2
- package/dist/commands/runtime-health-snapshot.js.map +1 -1
- package/dist/commands/runtime-init.d.ts +43 -0
- package/dist/commands/runtime-init.d.ts.map +1 -0
- package/dist/commands/runtime-init.js +264 -0
- package/dist/commands/runtime-init.js.map +1 -0
- package/dist/commands/runtime-internalization-context-trace.d.ts +25 -0
- package/dist/commands/runtime-internalization-context-trace.d.ts.map +1 -0
- package/dist/commands/runtime-internalization-context-trace.js +374 -0
- package/dist/commands/runtime-internalization-context-trace.js.map +1 -0
- package/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
- package/dist/commands/runtime-internalization-enqueue-successors.js +3 -1
- package/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
- package/dist/commands/runtime-internalization-integrity.d.ts.map +1 -1
- package/dist/commands/runtime-internalization-integrity.js +4 -2
- package/dist/commands/runtime-internalization-integrity.js.map +1 -1
- package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/dist/commands/runtime-internalization-run-once.js +20 -5
- package/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/dist/commands/runtime-internalization-run-rulehost.d.ts +1 -0
- package/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
- package/dist/commands/runtime-internalization-run-rulehost.js +149 -6
- package/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
- package/dist/commands/runtime-uat.d.ts.map +1 -1
- package/dist/commands/runtime-uat.guard.test.js +13 -15
- package/dist/commands/runtime-uat.guard.test.js.map +1 -1
- package/dist/commands/runtime-uat.js +4 -3
- package/dist/commands/runtime-uat.js.map +1 -1
- package/dist/config-reader.js +1 -1
- package/dist/config-reader.js.map +1 -1
- package/dist/index.js +54 -78
- package/dist/index.js.map +1 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +2 -0
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +1 -0
- package/dist/services/__tests__/evaluator-runner-deps.test.js +304 -0
- package/dist/services/__tests__/evaluator-runner-deps.test.js.map +1 -0
- package/dist/services/__tests__/rulehost-readiness.test.js.map +1 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +1 -1
- package/dist/services/config-doctor.d.ts.map +1 -1
- package/dist/services/config-doctor.js +9 -2
- package/dist/services/config-doctor.js.map +1 -1
- package/dist/services/pain-flood-simulation-runner.d.ts.map +1 -1
- package/dist/services/pain-flood-simulation-runner.js +9 -0
- package/dist/services/pain-flood-simulation-runner.js.map +1 -1
- package/dist/services/pd-config-loader.js +2 -2
- package/dist/services/pd-config-loader.js.map +1 -1
- package/dist/services/proven-channel-baseline-runner.d.ts.map +1 -1
- package/dist/services/proven-channel-baseline-runner.js +10 -2
- package/dist/services/proven-channel-baseline-runner.js.map +1 -1
- package/dist/services/quality-scorecard/data-extractor.js.map +1 -1
- package/dist/services/resolve-runtime-from-pd-config.js.map +1 -1
- package/dist/services/rulehost-pipeline-runner.d.ts +77 -1
- package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
- package/dist/services/rulehost-pipeline-runner.js +111 -7
- package/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/dist/services/rulehost-readiness.js.map +1 -1
- package/dist/services/runtime-adapter-resolver.d.ts +1 -0
- package/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
- package/dist/services/runtime-adapter-resolver.js +3 -0
- package/dist/services/runtime-adapter-resolver.js.map +1 -1
- package/dist/services/synthetic-baseline-runner.d.ts.map +1 -1
- package/dist/services/synthetic-baseline-runner.js +11 -0
- package/dist/services/synthetic-baseline-runner.js.map +1 -1
- package/dist/utils/production-workspace-guard.d.ts +4 -4
- package/dist/utils/production-workspace-guard.d.ts.map +1 -1
- package/dist/utils/production-workspace-guard.js +19 -16
- package/dist/utils/production-workspace-guard.js.map +1 -1
- package/dist/utils/production-workspace-guard.test.js +54 -19
- package/dist/utils/production-workspace-guard.test.js.map +1 -1
- package/package.json +8 -5
- package/src/commands/__tests__/intent-flag-wiring.test.ts +88 -3
- package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +73 -0
- package/src/commands/__tests__/rulecode-flag-wiring.test.ts +31 -24
- package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +12 -0
- package/src/commands/admission-gate.ts +30 -0
- package/src/commands/candidate.ts +74 -6
- package/src/commands/console.ts +40 -0
- package/src/commands/demo-story-a.ts +4 -2
- package/src/commands/diagnose.ts +158 -10
- package/src/commands/errors-list.ts +440 -0
- package/src/commands/health-codex.ts +249 -0
- package/src/commands/health.ts +60 -0
- package/src/commands/intent.ts +98 -29
- package/src/commands/pain-evidence.ts +6 -0
- package/src/commands/pain-record.ts +21 -0
- package/src/commands/pain-retry.ts +353 -35
- package/src/commands/proven-channel-baseline.ts +4 -2
- package/src/commands/runtime-activation.ts +657 -12
- package/src/commands/runtime-canary.ts +31 -5
- package/src/commands/runtime-health-snapshot.ts +4 -2
- package/src/commands/runtime-init.ts +305 -0
- package/src/commands/runtime-internalization-context-trace.ts +445 -0
- package/src/commands/runtime-internalization-enqueue-successors.ts +3 -1
- package/src/commands/runtime-internalization-integrity.ts +4 -2
- package/src/commands/runtime-internalization-run-once.ts +20 -5
- package/src/commands/runtime-internalization-run-rulehost.ts +159 -6
- package/src/commands/runtime-uat.guard.test.ts +14 -16
- package/src/commands/runtime-uat.ts +4 -3
- package/src/config-reader.ts +1 -1
- package/src/index.ts +69 -78
- package/src/services/__tests__/evaluator-runner-deps.test.ts +341 -0
- package/src/services/config-doctor.ts +9 -2
- package/src/services/pain-flood-simulation-runner.ts +9 -0
- package/src/services/pd-config-loader.ts +2 -2
- package/src/services/proven-channel-baseline-runner.ts +10 -3
- package/src/services/rulehost-pipeline-runner.ts +157 -6
- package/src/services/runtime-adapter-resolver.ts +4 -0
- package/src/services/synthetic-baseline-runner.ts +11 -0
- package/src/utils/production-workspace-guard.test.ts +62 -20
- package/src/utils/production-workspace-guard.ts +19 -16
- package/tests/bdd/cli-contract.steps.ts +343 -0
- package/tests/bdd/context-trace.steps.ts +229 -0
- package/tests/bdd/support/gherkin-loader.ts +147 -0
- package/tests/bdd/support/repo-root.ts +62 -0
- package/tests/bdd/support/vitest-bdd.ts +179 -0
- package/tests/commands/admission-gate-coverage.test.ts +79 -0
- package/tests/commands/candidate-audit-repair.test.ts +77 -0
- package/tests/commands/candidate-intake.test.ts +155 -10
- package/tests/commands/candidate-internalization-backfill.test.ts +30 -0
- package/tests/commands/cli-help-snapshot.test.ts +15 -1
- package/tests/commands/console-open.test.ts +19 -0
- package/tests/commands/diagnose.test.ts +619 -14
- package/tests/commands/errors-list.test.ts +678 -0
- package/tests/commands/health-codex.test.ts +243 -0
- package/tests/commands/health-host-wiring.test.ts +76 -0
- package/tests/commands/intent.test.ts +4 -4
- package/tests/commands/pain-record.test.ts +80 -0
- package/tests/commands/pain-retry.test.ts +94 -3
- package/tests/commands/run-rulehost-handler.test.ts +133 -0
- package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +227 -0
- package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +167 -0
- package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +262 -0
- package/tests/commands/runtime-activation-list-flag-wiring.test.ts +193 -0
- package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +222 -0
- package/tests/commands/runtime-activation.test.ts +1090 -5
- package/tests/commands/runtime-canary.test.ts +50 -0
- package/tests/commands/runtime-features.test.ts +2 -0
- package/tests/commands/runtime-init-empty-workspace.test.ts +234 -0
- package/tests/commands/runtime-init.test.ts +346 -0
- package/tests/commands/runtime-internalization-context-trace.test.ts +110 -0
- package/tests/commands/runtime-internalization.test.ts +2 -2
- package/tests/config-reader.test.ts +6 -5
- package/tests/e2e/cross-package-acceptance.test.ts +55 -13
- package/tests/services/mainline-snapshot-assembler.test.ts +6 -3
- package/tests/services/resolve-runtime-from-pd-config.test.ts +2 -0
- package/tests/services/rulehost-pipeline-runner.test.ts +1 -1
- package/vitest.config.ts +1 -1
|
@@ -528,3 +528,136 @@ describe('handleRunRuleHost — PRI-461 readiness integration', () => {
|
|
|
528
528
|
expect(exitCode).toBe(1);
|
|
529
529
|
});
|
|
530
530
|
});
|
|
531
|
+
|
|
532
|
+
// ── PR #1122: behavior-examples fail-fast + v2-aware text output ──────────
|
|
533
|
+
//
|
|
534
|
+
// CodeRabbit PR2 Comment 1 (P1): when --behavior-examples is provided but the
|
|
535
|
+
// file is missing or contains invalid JSON, the handler MUST return a
|
|
536
|
+
// structured error immediately instead of silently degrading to
|
|
537
|
+
// text_principle_only (rc-9-no-silent-fallback).
|
|
538
|
+
//
|
|
539
|
+
// CodeRabbit PR2 Comment 2 (P2): the text dry-run branch must use the same
|
|
540
|
+
// v2-aware capabilityStatus source as the JSON branch (behaviorExamplesReason-
|
|
541
|
+
// aware), not the stale resolvedRuntime.capabilityStatus.
|
|
542
|
+
//
|
|
543
|
+
// These tests require `rulecode_context_v2` enabled so the handler enters the
|
|
544
|
+
// v2 path where --behavior-examples is honored.
|
|
545
|
+
|
|
546
|
+
function writeContextV2EnabledConfig(workspaceDir: string): void {
|
|
547
|
+
const configDir = path.join(workspaceDir, '.pd');
|
|
548
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
549
|
+
const cfg = {
|
|
550
|
+
version: 1,
|
|
551
|
+
features: {
|
|
552
|
+
prompt: { category: 'core', enabled: true },
|
|
553
|
+
code_tool_hook: { category: 'core', enabled: true },
|
|
554
|
+
defer_archive: { category: 'core', enabled: true },
|
|
555
|
+
code_rule_capability: { category: 'core', enabled: true },
|
|
556
|
+
rulecode_context_v2: { category: 'core', enabled: true },
|
|
557
|
+
},
|
|
558
|
+
workspace: { default: workspaceDir },
|
|
559
|
+
runtimeProfiles: {
|
|
560
|
+
'pi-ai.default': { type: 'pi-ai', provider: 'anthropic', model: 'claude-sonnet', apiKeyEnv: 'ANTHROPIC_API_KEY' },
|
|
561
|
+
},
|
|
562
|
+
internalAgents: {
|
|
563
|
+
defaultRuntime: 'pi-ai.default',
|
|
564
|
+
agents: {
|
|
565
|
+
dreamer: { enabled: true, runtimeProfile: 'pi-ai.default' },
|
|
566
|
+
philosopher: { enabled: true, runtimeProfile: 'pi-ai.default' },
|
|
567
|
+
scribe: { enabled: true, runtimeProfile: 'pi-ai.default' },
|
|
568
|
+
artificer: { enabled: true, runtimeProfile: 'pi-ai.default' },
|
|
569
|
+
evaluator: { enabled: true, runtimeProfile: 'pi-ai.default' },
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
};
|
|
573
|
+
fs.writeFileSync(path.join(configDir, 'config.yaml'), yaml.dump(cfg), 'utf8');
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
describe('handleRunRuleHost — PR #1122 behavior-examples fail-fast (CodeRabbit Comment 1+2)', () => {
|
|
577
|
+
let workspaceDir: string;
|
|
578
|
+
let savedEnv: NodeJS.ProcessEnv;
|
|
579
|
+
|
|
580
|
+
beforeEach(() => {
|
|
581
|
+
workspaceDir = mkTmpDir();
|
|
582
|
+
savedEnv = { ...process.env };
|
|
583
|
+
process.env.ANTHROPIC_API_KEY = 'sk-ant-test-key';
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
afterEach(() => {
|
|
587
|
+
process.env = savedEnv;
|
|
588
|
+
try { fs.rmSync(workspaceDir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('returns status=failed with behavior_examples_unreadable reason in --json mode when --behavior-examples file does not exist', async () => {
|
|
592
|
+
writeContextV2EnabledConfig(workspaceDir);
|
|
593
|
+
const missingPath = path.join(workspaceDir, 'nonexistent-examples.json');
|
|
594
|
+
const { stdout, exitCode } = await captureStdio(() =>
|
|
595
|
+
handleRunRuleHost({
|
|
596
|
+
painId: 'pain-1',
|
|
597
|
+
dryRun: true,
|
|
598
|
+
json: true,
|
|
599
|
+
workspace: workspaceDir,
|
|
600
|
+
behaviorExamples: missingPath,
|
|
601
|
+
}),
|
|
602
|
+
);
|
|
603
|
+
const payload = parseJsonObject(stdout.trim());
|
|
604
|
+
expect(payload.status).toBe('failed');
|
|
605
|
+
expect(typeof payload.reason).toBe('string');
|
|
606
|
+
expect(payload.reason).toMatch(/^behavior_examples_unreadable:/);
|
|
607
|
+
expect(typeof payload.nextAction).toBe('string');
|
|
608
|
+
expect(exitCode).toBe(1);
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it('returns status=failed with behavior_examples_invalid reason in --json mode when --behavior-examples file has invalid JSON shape', async () => {
|
|
612
|
+
writeContextV2EnabledConfig(workspaceDir);
|
|
613
|
+
const examplesPath = path.join(workspaceDir, 'bad-examples.json');
|
|
614
|
+
// Valid JSON but missing required fields → behavior_examples_invalid: ...
|
|
615
|
+
fs.writeFileSync(examplesPath, JSON.stringify({ foo: 'bar' }), 'utf8');
|
|
616
|
+
const { stdout, exitCode } = await captureStdio(() =>
|
|
617
|
+
handleRunRuleHost({
|
|
618
|
+
painId: 'pain-1',
|
|
619
|
+
dryRun: true,
|
|
620
|
+
json: true,
|
|
621
|
+
workspace: workspaceDir,
|
|
622
|
+
behaviorExamples: examplesPath,
|
|
623
|
+
}),
|
|
624
|
+
);
|
|
625
|
+
const payload = parseJsonObject(stdout.trim());
|
|
626
|
+
expect(payload.status).toBe('failed');
|
|
627
|
+
expect(payload.reason).toMatch(/^behavior_examples_invalid:/);
|
|
628
|
+
expect(exitCode).toBe(1);
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
it('emits error on stderr in plain-text mode when --behavior-examples file does not exist', async () => {
|
|
632
|
+
writeContextV2EnabledConfig(workspaceDir);
|
|
633
|
+
const missingPath = path.join(workspaceDir, 'nonexistent-examples.json');
|
|
634
|
+
const { stdout, stderr, exitCode } = await captureStdio(() =>
|
|
635
|
+
handleRunRuleHost({
|
|
636
|
+
painId: 'pain-1',
|
|
637
|
+
dryRun: true,
|
|
638
|
+
workspace: workspaceDir,
|
|
639
|
+
behaviorExamples: missingPath,
|
|
640
|
+
}),
|
|
641
|
+
);
|
|
642
|
+
expect(exitCode).toBe(1);
|
|
643
|
+
expect(stderr).toMatch(/behavior_examples_unreadable:/);
|
|
644
|
+
// Plain-text mode must NOT emit a JSON object on stdout.
|
|
645
|
+
expect(stdout.trim()).toBe('');
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
it('text dry-run output uses v2-aware capabilityStatus when --behavior-examples is missing (CodeRabbit Comment 2)', async () => {
|
|
649
|
+
// With contextV2Enabled=true and no --behavior-examples, the handler sets
|
|
650
|
+
// behaviorExamplesReason='behavior_examples_missing'. The text dry-run
|
|
651
|
+
// branch must surface this reason in capabilityStatus (matching the JSON
|
|
652
|
+
// branch), not the stale resolvedRuntime.capabilityStatus.
|
|
653
|
+
writeContextV2EnabledConfig(workspaceDir);
|
|
654
|
+
const { stdout } = await captureStdio(() =>
|
|
655
|
+
handleRunRuleHost({
|
|
656
|
+
painId: 'pain-1',
|
|
657
|
+
dryRun: true,
|
|
658
|
+
workspace: workspaceDir,
|
|
659
|
+
}),
|
|
660
|
+
);
|
|
661
|
+
expect(stdout).toMatch(/code_rule_capability: OFF \(behavior_examples_missing\)/);
|
|
662
|
+
});
|
|
663
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser-level tests for `pd activation approve` flags (CLI gate rule 7).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `runtime-activation-promote-flag-wiring.test.ts`. Exercises the real
|
|
5
|
+
* `registerRuntimeActivationApproveCommand` 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
|
+
* - --approval-id / -a is required (Commander rejects missing required option)
|
|
11
|
+
* - --decided-by, --note, --json are registered
|
|
12
|
+
* - --workspace / -w shorthand is registered
|
|
13
|
+
* - --dry-run / --confirm / --no-json are NOT registered
|
|
14
|
+
*
|
|
15
|
+
* Handler-level behavior (approval dispatch, 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 { registerRuntimeActivationApproveCommand } 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 approve — flag wiring (CLI gate rule 7)', () => {
|
|
55
|
+
// ── Option metadata ──────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
it('registers -a, --approval-id as required option', () => {
|
|
58
|
+
const program = freshProgram();
|
|
59
|
+
const activationCmd = program.command('activation');
|
|
60
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
61
|
+
|
|
62
|
+
const opt = approveCmd.options.find((o) => o.long === '--approval-id');
|
|
63
|
+
expect(opt).toBeDefined();
|
|
64
|
+
expect(opt?.long).toBe('--approval-id');
|
|
65
|
+
expect(opt?.short).toBe('-a');
|
|
66
|
+
expect(opt?.required).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('registers --decided-by flag', () => {
|
|
70
|
+
const program = freshProgram();
|
|
71
|
+
const activationCmd = program.command('activation');
|
|
72
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
73
|
+
|
|
74
|
+
const opt = approveCmd.options.find((o) => o.long === '--decided-by');
|
|
75
|
+
expect(opt).toBeDefined();
|
|
76
|
+
expect(opt?.long).toBe('--decided-by');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('registers --note flag', () => {
|
|
80
|
+
const program = freshProgram();
|
|
81
|
+
const activationCmd = program.command('activation');
|
|
82
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
83
|
+
|
|
84
|
+
const opt = approveCmd.options.find((o) => o.long === '--note');
|
|
85
|
+
expect(opt).toBeDefined();
|
|
86
|
+
expect(opt?.long).toBe('--note');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('registers --json flag', () => {
|
|
90
|
+
const program = freshProgram();
|
|
91
|
+
const activationCmd = program.command('activation');
|
|
92
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
93
|
+
|
|
94
|
+
const opt = approveCmd.options.find((o) => o.long === '--json');
|
|
95
|
+
expect(opt).toBeDefined();
|
|
96
|
+
expect(opt?.long).toBe('--json');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('registers -w shorthand for --workspace', () => {
|
|
100
|
+
const program = freshProgram();
|
|
101
|
+
const activationCmd = program.command('activation');
|
|
102
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
103
|
+
|
|
104
|
+
const opt = approveCmd.options.find((o) => o.short === '-w');
|
|
105
|
+
expect(opt).toBeDefined();
|
|
106
|
+
expect(opt?.long).toBe('--workspace');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('does NOT register --dry-run', () => {
|
|
110
|
+
const program = freshProgram();
|
|
111
|
+
const activationCmd = program.command('activation');
|
|
112
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
113
|
+
|
|
114
|
+
const opt = approveCmd.options.find((o) => o.long === '--dry-run');
|
|
115
|
+
expect(opt).toBeUndefined();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('does NOT register --confirm', () => {
|
|
119
|
+
const program = freshProgram();
|
|
120
|
+
const activationCmd = program.command('activation');
|
|
121
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
122
|
+
|
|
123
|
+
const opt = approveCmd.options.find((o) => o.long === '--confirm');
|
|
124
|
+
expect(opt).toBeUndefined();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('does NOT register --no-json (no accidental negation)', () => {
|
|
128
|
+
const program = freshProgram();
|
|
129
|
+
const activationCmd = program.command('activation');
|
|
130
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
131
|
+
|
|
132
|
+
const noForm = approveCmd.options.find((o) => o.long === '--no-json');
|
|
133
|
+
expect(noForm).toBeUndefined();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// ── Parser-level tests (program.parseAsync) ───────────────────────────────
|
|
137
|
+
|
|
138
|
+
it('parses --approval-id and --json', async () => {
|
|
139
|
+
const program = freshProgram();
|
|
140
|
+
const activationCmd = program.command('activation');
|
|
141
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
142
|
+
const captured: CapturedAction = { opts: null };
|
|
143
|
+
attachCapture(approveCmd, captured);
|
|
144
|
+
|
|
145
|
+
await program.parseAsync(['node', 'pd', 'activation', 'approve', '--approval-id', 'apr-1', '--json']);
|
|
146
|
+
|
|
147
|
+
expect(captured.opts).not.toBeNull();
|
|
148
|
+
expect(captured.opts?.approvalId).toBe('apr-1');
|
|
149
|
+
expect(captured.opts?.json).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('parses -a shorthand for --approval-id', async () => {
|
|
153
|
+
const program = freshProgram();
|
|
154
|
+
const activationCmd = program.command('activation');
|
|
155
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
156
|
+
const captured: CapturedAction = { opts: null };
|
|
157
|
+
attachCapture(approveCmd, captured);
|
|
158
|
+
|
|
159
|
+
await program.parseAsync(['node', 'pd', 'activation', 'approve', '-a', 'apr-1']);
|
|
160
|
+
|
|
161
|
+
expect(captured.opts).not.toBeNull();
|
|
162
|
+
expect(captured.opts?.approvalId).toBe('apr-1');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('parses --decided-by with value', async () => {
|
|
166
|
+
const program = freshProgram();
|
|
167
|
+
const activationCmd = program.command('activation');
|
|
168
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
169
|
+
const captured: CapturedAction = { opts: null };
|
|
170
|
+
attachCapture(approveCmd, captured);
|
|
171
|
+
|
|
172
|
+
await program.parseAsync(['node', 'pd', 'activation', 'approve', '--approval-id', 'apr-1', '--decided-by', 'alice']);
|
|
173
|
+
|
|
174
|
+
expect(captured.opts).not.toBeNull();
|
|
175
|
+
expect(captured.opts?.decidedBy).toBe('alice');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('parses --note with value', async () => {
|
|
179
|
+
const program = freshProgram();
|
|
180
|
+
const activationCmd = program.command('activation');
|
|
181
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
182
|
+
const captured: CapturedAction = { opts: null };
|
|
183
|
+
attachCapture(approveCmd, captured);
|
|
184
|
+
|
|
185
|
+
await program.parseAsync(['node', 'pd', 'activation', 'approve', '--approval-id', 'apr-1', '--note', 'looks good']);
|
|
186
|
+
|
|
187
|
+
expect(captured.opts).not.toBeNull();
|
|
188
|
+
expect(captured.opts?.note).toBe('looks good');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('parses -w shorthand for --workspace', async () => {
|
|
192
|
+
const program = freshProgram();
|
|
193
|
+
const activationCmd = program.command('activation');
|
|
194
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
195
|
+
const captured: CapturedAction = { opts: null };
|
|
196
|
+
attachCapture(approveCmd, captured);
|
|
197
|
+
|
|
198
|
+
await program.parseAsync(['node', 'pd', 'activation', 'approve', '--approval-id', 'apr-1', '-w', '/tmp/test']);
|
|
199
|
+
|
|
200
|
+
expect(captured.opts).not.toBeNull();
|
|
201
|
+
expect(captured.opts?.workspace).toBe('/tmp/test');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('rejects missing --approval-id (required option)', async () => {
|
|
205
|
+
const program = freshProgram();
|
|
206
|
+
const activationCmd = program.command('activation');
|
|
207
|
+
registerRuntimeActivationApproveCommand(activationCmd);
|
|
208
|
+
|
|
209
|
+
// Commander should throw on missing required option
|
|
210
|
+
await expect(
|
|
211
|
+
program.parseAsync(['node', 'pd', 'activation', 'approve', '--json']),
|
|
212
|
+
).rejects.toThrow(/approval-id/);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('defaults --json to undefined when not passed', async () => {
|
|
216
|
+
const program = freshProgram();
|
|
217
|
+
const activationCmd = program.command('activation');
|
|
218
|
+
const approveCmd = registerRuntimeActivationApproveCommand(activationCmd);
|
|
219
|
+
const captured: CapturedAction = { opts: null };
|
|
220
|
+
attachCapture(approveCmd, captured);
|
|
221
|
+
|
|
222
|
+
await program.parseAsync(['node', 'pd', 'activation', 'approve', '--approval-id', 'apr-1']);
|
|
223
|
+
|
|
224
|
+
expect(captured.opts).not.toBeNull();
|
|
225
|
+
expect(captured.opts?.json).toBeUndefined();
|
|
226
|
+
});
|
|
227
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser-level tests for `pd activation deactivate` flags (CLI gate rule 7).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `runtime-activation-promote-flag-wiring.test.ts`. Exercises the real
|
|
5
|
+
* `registerRuntimeActivationDeactivateCommand` 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
|
+
* - --activation-id is required (Commander rejects missing required option)
|
|
11
|
+
* - --json is registered
|
|
12
|
+
* - --workspace / -w shorthand is registered
|
|
13
|
+
* - --dry-run / --confirm / --no-json are NOT registered
|
|
14
|
+
*
|
|
15
|
+
* Handler-level behavior (deactivation idempotency, JSON output shape,
|
|
16
|
+
* refusal reasons) is covered by runtime-activation.test.ts.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { describe, it, expect } from 'vitest';
|
|
20
|
+
import { Command } from 'commander';
|
|
21
|
+
|
|
22
|
+
import { registerRuntimeActivationDeactivateCommand } 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 deactivate — flag wiring (CLI gate rule 7)', () => {
|
|
55
|
+
// ── Option metadata ──────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
it('registers --activation-id as required option', () => {
|
|
58
|
+
const program = freshProgram();
|
|
59
|
+
const activationCmd = program.command('activation');
|
|
60
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
61
|
+
|
|
62
|
+
const opt = deactivateCmd.options.find((o) => o.long === '--activation-id');
|
|
63
|
+
expect(opt).toBeDefined();
|
|
64
|
+
expect(opt?.long).toBe('--activation-id');
|
|
65
|
+
expect(opt?.required).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('registers --json flag', () => {
|
|
69
|
+
const program = freshProgram();
|
|
70
|
+
const activationCmd = program.command('activation');
|
|
71
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
72
|
+
|
|
73
|
+
const opt = deactivateCmd.options.find((o) => o.long === '--json');
|
|
74
|
+
expect(opt).toBeDefined();
|
|
75
|
+
expect(opt?.long).toBe('--json');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('registers -w shorthand for --workspace', () => {
|
|
79
|
+
const program = freshProgram();
|
|
80
|
+
const activationCmd = program.command('activation');
|
|
81
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
82
|
+
|
|
83
|
+
const opt = deactivateCmd.options.find((o) => o.short === '-w');
|
|
84
|
+
expect(opt).toBeDefined();
|
|
85
|
+
expect(opt?.long).toBe('--workspace');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('does NOT register --dry-run', () => {
|
|
89
|
+
const program = freshProgram();
|
|
90
|
+
const activationCmd = program.command('activation');
|
|
91
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
92
|
+
|
|
93
|
+
const opt = deactivateCmd.options.find((o) => o.long === '--dry-run');
|
|
94
|
+
expect(opt).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('does NOT register --confirm', () => {
|
|
98
|
+
const program = freshProgram();
|
|
99
|
+
const activationCmd = program.command('activation');
|
|
100
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
101
|
+
|
|
102
|
+
const opt = deactivateCmd.options.find((o) => o.long === '--confirm');
|
|
103
|
+
expect(opt).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('does NOT register --no-json (no accidental negation)', () => {
|
|
107
|
+
const program = freshProgram();
|
|
108
|
+
const activationCmd = program.command('activation');
|
|
109
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
110
|
+
|
|
111
|
+
const noForm = deactivateCmd.options.find((o) => o.long === '--no-json');
|
|
112
|
+
expect(noForm).toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ── Parser-level tests (program.parseAsync) ───────────────────────────────
|
|
116
|
+
|
|
117
|
+
it('parses --activation-id and --json', async () => {
|
|
118
|
+
const program = freshProgram();
|
|
119
|
+
const activationCmd = program.command('activation');
|
|
120
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
121
|
+
const captured: CapturedAction = { opts: null };
|
|
122
|
+
attachCapture(deactivateCmd, captured);
|
|
123
|
+
|
|
124
|
+
await program.parseAsync(['node', 'pd', 'activation', 'deactivate', '--activation-id', 'act-1', '--json']);
|
|
125
|
+
|
|
126
|
+
expect(captured.opts).not.toBeNull();
|
|
127
|
+
expect(captured.opts?.activationId).toBe('act-1');
|
|
128
|
+
expect(captured.opts?.json).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('parses -w shorthand for --workspace', async () => {
|
|
132
|
+
const program = freshProgram();
|
|
133
|
+
const activationCmd = program.command('activation');
|
|
134
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
135
|
+
const captured: CapturedAction = { opts: null };
|
|
136
|
+
attachCapture(deactivateCmd, captured);
|
|
137
|
+
|
|
138
|
+
await program.parseAsync(['node', 'pd', 'activation', 'deactivate', '--activation-id', 'act-1', '-w', '/tmp/test']);
|
|
139
|
+
|
|
140
|
+
expect(captured.opts).not.toBeNull();
|
|
141
|
+
expect(captured.opts?.workspace).toBe('/tmp/test');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('rejects missing --activation-id (required option)', async () => {
|
|
145
|
+
const program = freshProgram();
|
|
146
|
+
const activationCmd = program.command('activation');
|
|
147
|
+
registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
148
|
+
|
|
149
|
+
// Commander should throw on missing required option
|
|
150
|
+
await expect(
|
|
151
|
+
program.parseAsync(['node', 'pd', 'activation', 'deactivate', '--json']),
|
|
152
|
+
).rejects.toThrow(/activation-id/);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('defaults --json to undefined when not passed', async () => {
|
|
156
|
+
const program = freshProgram();
|
|
157
|
+
const activationCmd = program.command('activation');
|
|
158
|
+
const deactivateCmd = registerRuntimeActivationDeactivateCommand(activationCmd);
|
|
159
|
+
const captured: CapturedAction = { opts: null };
|
|
160
|
+
attachCapture(deactivateCmd, captured);
|
|
161
|
+
|
|
162
|
+
await program.parseAsync(['node', 'pd', 'activation', 'deactivate', '--activation-id', 'act-1']);
|
|
163
|
+
|
|
164
|
+
expect(captured.opts).not.toBeNull();
|
|
165
|
+
expect(captured.opts?.json).toBeUndefined();
|
|
166
|
+
});
|
|
167
|
+
});
|