@dommaker/harness 0.16.9 → 0.17.1
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/CHANGELOG.md +39 -0
- package/README.md +33 -32
- package/bin/harness.js +33 -20
- package/dist/cli/commands/check.d.ts +3 -2
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +69 -36
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/constraints-report.d.ts +42 -0
- package/dist/cli/commands/constraints-report.d.ts.map +1 -0
- package/dist/cli/commands/constraints-report.js +233 -0
- package/dist/cli/commands/constraints-report.js.map +1 -0
- package/dist/cli/commands/constraints-retire.d.ts +71 -0
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -0
- package/dist/cli/commands/constraints-retire.js +384 -0
- package/dist/cli/commands/constraints-retire.js.map +1 -0
- package/dist/cli/commands/constraints.d.ts +1 -1
- package/dist/cli/commands/constraints.d.ts.map +1 -1
- package/dist/cli/commands/constraints.js +4 -4
- package/dist/cli/commands/constraints.js.map +1 -1
- package/dist/cli/commands/index.d.ts +2 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +10 -4
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +20 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +81 -59
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/report.js +4 -4
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +3 -4
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +5 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/capabilities-syncer.js +2 -10
- package/dist/cli/commands/sync-docs/capabilities-syncer.js.map +1 -1
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +1 -5
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts +7 -0
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-parser.js +13 -0
- package/dist/core/constraints/capabilities-parser.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +13 -5
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +62 -25
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts +9 -2
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +55 -22
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts +3 -0
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.js +8 -2
- package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.d.ts +1 -0
- package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js +39 -0
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/index.d.ts +8 -4
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +29 -46
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/iron-flags.d.ts +6 -7
- package/dist/core/constraints/checkers/iron-flags.d.ts.map +1 -1
- package/dist/core/constraints/checkers/iron-flags.js +10 -17
- package/dist/core/constraints/checkers/iron-flags.js.map +1 -1
- package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts +13 -0
- package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts.map +1 -0
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js +91 -0
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js.map +1 -0
- package/dist/core/constraints/checkers/types.d.ts +15 -4
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +16 -4
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/context-builder.d.ts +6 -3
- package/dist/core/constraints/context-builder.d.ts.map +1 -1
- package/dist/core/constraints/context-builder.js +29 -20
- package/dist/core/constraints/context-builder.js.map +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts +6 -2
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +29 -572
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.d.ts +6 -2
- package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.js +48 -231
- package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
- package/dist/core/constraints/definitions/prompts.d.ts +12 -0
- package/dist/core/constraints/definitions/prompts.d.ts.map +1 -0
- package/dist/core/constraints/definitions/prompts.js +405 -0
- package/dist/core/constraints/definitions/prompts.js.map +1 -0
- package/dist/core/constraints/definitions.d.ts +15 -9
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +18 -12
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/constraints/index.d.ts +3 -2
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +8 -2
- package/dist/core/constraints/index.js.map +1 -1
- package/dist/core/constraints/injection-drift.d.ts +48 -0
- package/dist/core/constraints/injection-drift.d.ts.map +1 -0
- package/dist/core/constraints/injection-drift.js +140 -0
- package/dist/core/constraints/injection-drift.js.map +1 -0
- package/dist/core/constraints/injection-renderer.d.ts +23 -0
- package/dist/core/constraints/injection-renderer.d.ts.map +1 -0
- package/dist/core/constraints/injection-renderer.js +44 -0
- package/dist/core/constraints/injection-renderer.js.map +1 -0
- package/dist/core/constraints/interceptor.d.ts.map +1 -1
- package/dist/core/constraints/interceptor.js +3 -2
- package/dist/core/constraints/interceptor.js.map +1 -1
- package/dist/core/constraints/usage-report.d.ts +95 -0
- package/dist/core/constraints/usage-report.d.ts.map +1 -0
- package/dist/core/constraints/usage-report.js +206 -0
- package/dist/core/constraints/usage-report.js.map +1 -0
- package/dist/core/effective-constraints.d.ts +47 -0
- package/dist/core/effective-constraints.d.ts.map +1 -0
- package/dist/core/effective-constraints.js +60 -0
- package/dist/core/effective-constraints.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +17 -2
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +55 -8
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/dashboard/data.d.ts +1 -9
- package/dist/dashboard/data.d.ts.map +1 -1
- package/dist/dashboard/data.js +7 -15
- package/dist/dashboard/data.js.map +1 -1
- package/dist/dashboard/types.d.ts +13 -1
- package/dist/dashboard/types.d.ts.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/monitoring/index.d.ts +0 -2
- package/dist/monitoring/index.d.ts.map +1 -1
- package/dist/monitoring/index.js +0 -2
- package/dist/monitoring/index.js.map +1 -1
- package/dist/monitoring/knowledge-evolver.d.ts +1 -1
- package/dist/monitoring/knowledge-evolver.js +1 -1
- package/dist/monitoring/trace-analyzer.d.ts +1 -1
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +16 -10
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/monitoring/traces.d.ts +2 -1
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +5 -3
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/presets/standard.d.ts +3 -1
- package/dist/presets/standard.d.ts.map +1 -1
- package/dist/presets/standard.js +18 -8
- package/dist/presets/standard.js.map +1 -1
- package/dist/types/constraint.d.ts +51 -11
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +8 -4
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/monitoring-types.d.ts +2 -63
- package/dist/types/monitoring-types.d.ts.map +1 -1
- package/dist/types/monitoring-types.js +2 -2
- package/dist/types/project-config.d.ts +26 -1
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/types/trace.d.ts +16 -7
- package/dist/types/trace.d.ts.map +1 -1
- package/dist/types/trace.js +8 -0
- package/dist/types/trace.js.map +1 -1
- package/package.json +1 -1
- package/src/CONTEXT.md +2 -2
- package/src/__tests__/checker-extra.test.ts +228 -333
- package/src/__tests__/checker.test.ts +87 -724
- package/src/__tests__/constraint-doctor.test.ts +5 -5
- package/src/__tests__/doctor-extra.test.ts +164 -0
- package/src/__tests__/effective-constraints.test.ts +147 -0
- package/src/__tests__/extend-exceptions.test.ts +3 -3
- package/src/__tests__/iron-laws.test.ts +115 -91
- package/src/__tests__/no-hardcoded-credentials.test.ts +90 -0
- package/src/__tests__/presets.test.ts +7 -7
- package/src/__tests__/project-config-loader-extra.test.ts +41 -4
- package/src/__tests__/skip-semantics.test.ts +322 -0
- package/src/cli/commands/CONTEXT.md +5 -3
- package/src/cli/commands/__tests__/check-drift.test.ts +127 -0
- package/src/cli/commands/__tests__/check-skip-output.test.ts +128 -0
- package/src/cli/commands/__tests__/check.test.ts +14 -25
- package/src/cli/commands/__tests__/constraints-report.test.ts +327 -0
- package/src/cli/commands/__tests__/constraints-retire.test.ts +283 -0
- package/src/cli/commands/__tests__/init-injection.test.ts +234 -0
- package/src/cli/commands/__tests__/status-extra.test.ts +11 -11
- package/src/cli/commands/__tests__/status.test.ts +1 -1
- package/src/cli/commands/check.ts +72 -38
- package/src/cli/commands/constraints-report.ts +234 -0
- package/src/cli/commands/constraints-retire.ts +443 -0
- package/src/cli/commands/constraints.ts +5 -5
- package/src/cli/commands/index.ts +2 -1
- package/src/cli/commands/init.ts +94 -66
- package/src/cli/commands/report.ts +6 -6
- package/src/cli/commands/status.ts +3 -4
- package/src/cli/commands/sync-docs/capabilities-syncer.ts +5 -7
- package/src/cli/commands/validate.ts +1 -5
- package/src/core/CONTEXT.md +7 -4
- package/src/core/constraints/__tests__/injection-drift.test.ts +164 -0
- package/src/core/constraints/__tests__/interceptor.test.ts +4 -0
- package/src/core/constraints/capabilities-parser.ts +13 -0
- package/src/core/constraints/checker.ts +73 -28
- package/src/core/constraints/checkers/capability-sync.ts +72 -29
- package/src/core/constraints/checkers/context-doc-sync.ts +9 -2
- package/src/core/constraints/checkers/docs-freshness.ts +43 -0
- package/src/core/constraints/checkers/index.ts +38 -71
- package/src/core/constraints/checkers/iron-flags.ts +13 -49
- package/src/core/constraints/checkers/no-hardcoded-credentials.ts +93 -0
- package/src/core/constraints/checkers/types.ts +27 -5
- package/src/core/constraints/context-builder.ts +28 -19
- package/src/core/constraints/definitions/guidelines.ts +29 -597
- package/src/core/constraints/definitions/iron-laws.ts +48 -239
- package/src/core/constraints/definitions/prompts.ts +419 -0
- package/src/core/constraints/definitions.ts +18 -11
- package/src/core/constraints/index.ts +10 -1
- package/src/core/constraints/injection-drift.ts +139 -0
- package/src/core/constraints/injection-renderer.ts +44 -0
- package/src/core/constraints/interceptor.ts +3 -2
- package/src/core/constraints/usage-report.ts +254 -0
- package/src/core/effective-constraints.ts +85 -0
- package/src/core/index.ts +4 -1
- package/src/core/project-config-loader.ts +59 -9
- package/src/dashboard/__tests__/data.test.ts +5 -12
- package/src/dashboard/data.ts +9 -19
- package/src/dashboard/types.ts +18 -1
- package/src/index.ts +0 -12
- package/src/knowledge/CONTEXT.md +2 -2
- package/src/monitoring/CONTEXT.md +3 -4
- package/src/monitoring/index.ts +0 -2
- package/src/monitoring/knowledge-evolver.ts +1 -1
- package/src/monitoring/trace-analyzer.ts +15 -10
- package/src/monitoring/traces.ts +10 -6
- package/src/presets/__tests__/standard.test.ts +11 -9
- package/src/presets/standard.ts +24 -15
- package/src/types/constraint.ts +59 -14
- package/src/types/index.ts +1 -3
- package/src/types/monitoring-types.ts +2 -84
- package/src/types/project-config.ts +30 -1
- package/src/types/trace.ts +18 -7
- package/src/verification/CONTEXT.md +1 -1
- package/dist/cli/commands/flow.d.ts +0 -22
- package/dist/cli/commands/flow.d.ts.map +0 -1
- package/dist/cli/commands/flow.js +0 -275
- package/dist/cli/commands/flow.js.map +0 -1
- package/dist/constraints/lifecycle-runner.d.ts +0 -52
- package/dist/constraints/lifecycle-runner.d.ts.map +0 -1
- package/dist/constraints/lifecycle-runner.js +0 -151
- package/dist/constraints/lifecycle-runner.js.map +0 -1
- package/dist/constraints/registry.d.ts +0 -27
- package/dist/constraints/registry.d.ts.map +0 -1
- package/dist/constraints/registry.js +0 -128
- package/dist/constraints/registry.js.map +0 -1
- package/dist/constraints/types.d.ts +0 -53
- package/dist/constraints/types.d.ts.map +0 -1
- package/dist/constraints/types.js +0 -8
- package/dist/constraints/types.js.map +0 -1
- package/dist/core/constraints/checkers/always-pass.d.ts +0 -17
- package/dist/core/constraints/checkers/always-pass.d.ts.map +0 -1
- package/dist/core/constraints/checkers/always-pass.js +0 -23
- package/dist/core/constraints/checkers/always-pass.js.map +0 -1
- package/dist/core/constraints/checkers/guideline-flags.d.ts +0 -9
- package/dist/core/constraints/checkers/guideline-flags.d.ts.map +0 -1
- package/dist/core/constraints/checkers/guideline-flags.js +0 -13
- package/dist/core/constraints/checkers/guideline-flags.js.map +0 -1
- package/dist/core/constraints/checkers/no-any-type.d.ts +0 -6
- package/dist/core/constraints/checkers/no-any-type.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-any-type.js +0 -42
- package/dist/core/constraints/checkers/no-any-type.js.map +0 -1
- package/dist/core/constraints/checkers/no-excuse-patterns.d.ts +0 -6
- package/dist/core/constraints/checkers/no-excuse-patterns.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-excuse-patterns.js +0 -25
- package/dist/core/constraints/checkers/no-excuse-patterns.js.map +0 -1
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.d.ts +0 -6
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.js +0 -34
- package/dist/core/constraints/checkers/no-fuzzy-completion-claim.js.map +0 -1
- package/dist/core/constraints/checkers/no-performative-agreement.d.ts +0 -8
- package/dist/core/constraints/checkers/no-performative-agreement.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-performative-agreement.js +0 -23
- package/dist/core/constraints/checkers/no-performative-agreement.js.map +0 -1
- package/dist/core/constraints/checkers/no-simplification-without-approval.d.ts +0 -6
- package/dist/core/constraints/checkers/no-simplification-without-approval.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-simplification-without-approval.js +0 -30
- package/dist/core/constraints/checkers/no-simplification-without-approval.js.map +0 -1
- package/dist/core/constraints/checkers/test-coverage.d.ts +0 -6
- package/dist/core/constraints/checkers/test-coverage.d.ts.map +0 -1
- package/dist/core/constraints/checkers/test-coverage.js +0 -33
- package/dist/core/constraints/checkers/test-coverage.js.map +0 -1
- package/dist/core/constraints/checkers/yagni.d.ts +0 -8
- package/dist/core/constraints/checkers/yagni.d.ts.map +0 -1
- package/dist/core/constraints/checkers/yagni.js +0 -96
- package/dist/core/constraints/checkers/yagni.js.map +0 -1
- package/dist/core/constraints/definitions/tips.d.ts +0 -7
- package/dist/core/constraints/definitions/tips.d.ts.map +0 -1
- package/dist/core/constraints/definitions/tips.js +0 -62
- package/dist/core/constraints/definitions/tips.js.map +0 -1
- package/dist/evolution/auto-evolve.d.ts +0 -35
- package/dist/evolution/auto-evolve.d.ts.map +0 -1
- package/dist/evolution/auto-evolve.js +0 -64
- package/dist/evolution/auto-evolve.js.map +0 -1
- package/dist/evolution/index.d.ts +0 -2
- package/dist/evolution/index.d.ts.map +0 -1
- package/dist/evolution/index.js +0 -18
- package/dist/evolution/index.js.map +0 -1
- package/dist/monitoring/constraint-evolver.d.ts +0 -120
- package/dist/monitoring/constraint-evolver.d.ts.map +0 -1
- package/dist/monitoring/constraint-evolver.js +0 -410
- package/dist/monitoring/constraint-evolver.js.map +0 -1
- package/src/__tests__/constraint-evolver.test.ts +0 -405
- package/src/__tests__/doctor-evolver.test.ts +0 -381
- package/src/cli/commands/__tests__/flow.test.ts +0 -343
- package/src/cli/commands/flow.ts +0 -277
- package/src/constraints/__tests__/lifecycle-runner.test.ts +0 -246
- package/src/constraints/__tests__/registry.test.ts +0 -196
- package/src/constraints/lifecycle-runner.ts +0 -184
- package/src/constraints/registry.ts +0 -134
- package/src/constraints/types.ts +0 -59
- package/src/core/constraints/checkers/always-pass.ts +0 -22
- package/src/core/constraints/checkers/guideline-flags.ts +0 -30
- package/src/core/constraints/checkers/no-any-type.ts +0 -42
- package/src/core/constraints/checkers/no-excuse-patterns.ts +0 -24
- package/src/core/constraints/checkers/no-fuzzy-completion-claim.ts +0 -33
- package/src/core/constraints/checkers/no-performative-agreement.ts +0 -22
- package/src/core/constraints/checkers/no-simplification-without-approval.ts +0 -29
- package/src/core/constraints/checkers/test-coverage.ts +0 -35
- package/src/core/constraints/checkers/yagni.ts +0 -65
- package/src/core/constraints/definitions/tips.ts +0 -63
- package/src/evolution/CONTEXT.md +0 -22
- package/src/evolution/__tests__/auto-evolve.test.ts +0 -319
- package/src/evolution/auto-evolve.ts +0 -98
- package/src/evolution/index.ts +0 -1
- package/src/monitoring/constraint-evolver.ts +0 -501
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ConstraintLifecycleRunner 测试
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, beforeEach } from '@jest/globals';
|
|
6
|
-
import { ConstraintLifecycleRunner, type ExecutionResult } from '../lifecycle-runner';
|
|
7
|
-
import { ConstraintRegistry } from '../registry';
|
|
8
|
-
import type { ConstraintProposal } from '../../types/monitoring-types';
|
|
9
|
-
|
|
10
|
-
function makeProposal(overrides: Partial<ConstraintProposal> = {}): ConstraintProposal {
|
|
11
|
-
return {
|
|
12
|
-
id: 'test-proposal-1',
|
|
13
|
-
proposedAt: Date.now(),
|
|
14
|
-
diagnosisId: 'diag-1',
|
|
15
|
-
constraintId: 'no_fix_without_root_cause',
|
|
16
|
-
type: 'change_level',
|
|
17
|
-
content: { proposed: 'tip', description: '降级为 tip' },
|
|
18
|
-
reasoning: 'low intercept rate',
|
|
19
|
-
expectedOutcome: 'fewer interruptions',
|
|
20
|
-
risk: { level: 'low', description: 'safe' },
|
|
21
|
-
implementation: { files: [], linesChanged: 0, testsRequired: false },
|
|
22
|
-
status: 'accepted',
|
|
23
|
-
...overrides,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe('ConstraintLifecycleRunner', () => {
|
|
28
|
-
let runner: ConstraintLifecycleRunner;
|
|
29
|
-
let registry: ConstraintRegistry;
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
registry = new ConstraintRegistry();
|
|
33
|
-
runner = new ConstraintLifecycleRunner(registry);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('execute - change_level', () => {
|
|
37
|
-
it('应该成功降级质量层约束', () => {
|
|
38
|
-
const proposal = makeProposal({
|
|
39
|
-
constraintId: 'no_fix_without_root_cause',
|
|
40
|
-
type: 'change_level',
|
|
41
|
-
content: { proposed: 'tip', description: '降级' },
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const result = runner.execute(proposal);
|
|
45
|
-
|
|
46
|
-
expect(result.success).toBe(true);
|
|
47
|
-
expect(result.action).toBe('degrade');
|
|
48
|
-
expect(result.details).toContain('Degraded');
|
|
49
|
-
|
|
50
|
-
// 验证 registry 状态已改变
|
|
51
|
-
const constraint = registry.get('no_fix_without_root_cause');
|
|
52
|
-
expect(constraint?.deprecationStatus).toBe('deprecated');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('应该拒绝安全层约束的 level 变更', () => {
|
|
56
|
-
const proposal = makeProposal({
|
|
57
|
-
constraintId: 'no_bypass_checkpoint',
|
|
58
|
-
type: 'change_level',
|
|
59
|
-
content: { proposed: 'guideline', description: '降级' },
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const result = runner.execute(proposal);
|
|
63
|
-
|
|
64
|
-
expect(result.success).toBe(false);
|
|
65
|
-
expect(result.details).toContain('safety-layer');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('应该返回失败当约束不存在', () => {
|
|
69
|
-
const proposal = makeProposal({
|
|
70
|
-
constraintId: 'nonexistent_constraint',
|
|
71
|
-
type: 'change_level',
|
|
72
|
-
content: { proposed: 'tip', description: '降级' },
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const result = runner.execute(proposal);
|
|
76
|
-
|
|
77
|
-
expect(result.success).toBe(false);
|
|
78
|
-
expect(result.details).toContain('not found');
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('execute - add_exception', () => {
|
|
83
|
-
it('应该成功添加例外', () => {
|
|
84
|
-
const proposal = makeProposal({
|
|
85
|
-
constraintId: 'no_fix_without_root_cause',
|
|
86
|
-
type: 'add_exception',
|
|
87
|
-
content: { proposed: 'new_exception', description: '新增例外' },
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const result = runner.execute(proposal);
|
|
91
|
-
|
|
92
|
-
expect(result.success).toBe(true);
|
|
93
|
-
expect(result.action).toBe('add_exception');
|
|
94
|
-
expect(result.details).toContain('new_exception');
|
|
95
|
-
|
|
96
|
-
const constraint = registry.get('no_fix_without_root_cause');
|
|
97
|
-
expect(constraint?.exceptions).toContain('new_exception');
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('应该拒绝重复的例外', () => {
|
|
101
|
-
const proposal = makeProposal({
|
|
102
|
-
constraintId: 'no_fix_without_root_cause',
|
|
103
|
-
type: 'add_exception',
|
|
104
|
-
content: { proposed: 'simple_typo', description: '重复例外' },
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const result = runner.execute(proposal);
|
|
108
|
-
|
|
109
|
-
expect(result.success).toBe(false);
|
|
110
|
-
expect(result.details).toContain('already exists');
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('execute - adjust_trigger', () => {
|
|
115
|
-
it('应该成功修改触发条件', () => {
|
|
116
|
-
const proposal = makeProposal({
|
|
117
|
-
constraintId: 'no_fix_without_root_cause',
|
|
118
|
-
type: 'adjust_trigger',
|
|
119
|
-
content: { proposed: ['code_implementation', 'code_implementation'], description: '扩展触发' },
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const result = runner.execute(proposal);
|
|
123
|
-
|
|
124
|
-
expect(result.success).toBe(true);
|
|
125
|
-
expect(result.action).toBe('adjust_trigger');
|
|
126
|
-
|
|
127
|
-
const constraint = registry.get('no_fix_without_root_cause');
|
|
128
|
-
expect(constraint?.trigger).toEqual(['code_implementation', 'code_implementation']);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('execute - modify_message', () => {
|
|
133
|
-
it('应该成功修改消息', () => {
|
|
134
|
-
const proposal = makeProposal({
|
|
135
|
-
constraintId: 'no_fix_without_root_cause',
|
|
136
|
-
type: 'modify_message',
|
|
137
|
-
content: { proposed: '新的消息', description: '更新消息' },
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const result = runner.execute(proposal);
|
|
141
|
-
|
|
142
|
-
expect(result.success).toBe(true);
|
|
143
|
-
expect(result.action).toBe('modify_message');
|
|
144
|
-
|
|
145
|
-
const constraint = registry.get('no_fix_without_root_cause');
|
|
146
|
-
expect(constraint?.message).toBe('新的消息');
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe('execute - unsupported type', () => {
|
|
151
|
-
it('应该拒绝不支持的提案类型', () => {
|
|
152
|
-
const proposal = makeProposal({
|
|
153
|
-
type: 'new_constraint' as any,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const result = runner.execute(proposal);
|
|
157
|
-
|
|
158
|
-
expect(result.success).toBe(false);
|
|
159
|
-
expect(result.details).toContain('Unsupported');
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe('executeBatch', () => {
|
|
164
|
-
it('应该批量执行多个提案', () => {
|
|
165
|
-
const proposals = [
|
|
166
|
-
makeProposal({
|
|
167
|
-
id: 'p1',
|
|
168
|
-
constraintId: 'no_fix_without_root_cause',
|
|
169
|
-
type: 'modify_message',
|
|
170
|
-
content: { proposed: '消息1', description: '更新' },
|
|
171
|
-
}),
|
|
172
|
-
makeProposal({
|
|
173
|
-
id: 'p2',
|
|
174
|
-
constraintId: 'no_code_without_test',
|
|
175
|
-
type: 'modify_message',
|
|
176
|
-
content: { proposed: '消息2', description: '更新' },
|
|
177
|
-
}),
|
|
178
|
-
];
|
|
179
|
-
|
|
180
|
-
const results = runner.executeBatch(proposals);
|
|
181
|
-
|
|
182
|
-
expect(results).toHaveLength(2);
|
|
183
|
-
expect(results[0].success).toBe(true);
|
|
184
|
-
expect(results[1].success).toBe(true);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
describe('rollbackConstraint', () => {
|
|
189
|
-
it('应该成功回滚已降级的约束', () => {
|
|
190
|
-
// 先降级
|
|
191
|
-
const proposal = makeProposal({
|
|
192
|
-
constraintId: 'no_fix_without_root_cause',
|
|
193
|
-
type: 'change_level',
|
|
194
|
-
content: { proposed: 'tip', description: '降级' },
|
|
195
|
-
});
|
|
196
|
-
runner.execute(proposal);
|
|
197
|
-
|
|
198
|
-
const constraint = registry.get('no_fix_without_root_cause');
|
|
199
|
-
expect(constraint?.deprecationStatus).toBe('deprecated');
|
|
200
|
-
|
|
201
|
-
// 回滚
|
|
202
|
-
const success = runner.rollbackConstraint('no_fix_without_root_cause', 'guideline');
|
|
203
|
-
expect(success).toBe(true);
|
|
204
|
-
|
|
205
|
-
const after = registry.get('no_fix_without_root_cause');
|
|
206
|
-
expect(after?.deprecationStatus).toBe('active');
|
|
207
|
-
expect(after?.level).toBe('guideline');
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
describe('scheduleDeprecation', () => {
|
|
212
|
-
it('应该成功设置弃用计划', () => {
|
|
213
|
-
const success = runner.scheduleDeprecation('no_fix_without_root_cause', {
|
|
214
|
-
targetLevel: 'tip',
|
|
215
|
-
reason: 'low usage',
|
|
216
|
-
rollbackable: true,
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
expect(success).toBe(true);
|
|
220
|
-
|
|
221
|
-
const constraint = registry.get('no_fix_without_root_cause');
|
|
222
|
-
expect(constraint?.deprecationStatus).toBe('scheduled');
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('应该拒绝安全层约束的弃用计划', () => {
|
|
226
|
-
const success = runner.scheduleDeprecation('no_bypass_checkpoint', {
|
|
227
|
-
targetLevel: 'guideline',
|
|
228
|
-
reason: 'test',
|
|
229
|
-
rollbackable: false,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
expect(success).toBe(false);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe('getRegistry', () => {
|
|
237
|
-
it('应该返回内部 registry 实例', () => {
|
|
238
|
-
expect(runner.getRegistry()).toBe(registry);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('应该在无参数时创建默认 registry', () => {
|
|
242
|
-
const defaultRunner = new ConstraintLifecycleRunner();
|
|
243
|
-
expect(defaultRunner.getRegistry()).toBeDefined();
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
});
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ConstraintRegistry 测试
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { ConstraintRegistry } from '../registry';
|
|
6
|
-
import { IRON_LAWS, GUIDELINES, TIPS } from '../../core/constraints/definitions';
|
|
7
|
-
|
|
8
|
-
const SAFETY_COUNT = Object.keys(IRON_LAWS).length; // 7
|
|
9
|
-
const QUALITY_COUNT = Object.keys(GUIDELINES).length + Object.keys(TIPS).length; // 13
|
|
10
|
-
|
|
11
|
-
describe('ConstraintRegistry', () => {
|
|
12
|
-
let registry: ConstraintRegistry;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
registry = new ConstraintRegistry();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('get', () => {
|
|
19
|
-
it('应该获取安全层约束', () => {
|
|
20
|
-
const constraint = registry.get('no_bypass_checkpoint');
|
|
21
|
-
expect(constraint).toBeDefined();
|
|
22
|
-
expect(constraint?.layer).toBe('safety');
|
|
23
|
-
expect(constraint?.permanent).toBe(false); // 所有层级均可退化
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('应该获取质量层约束', () => {
|
|
27
|
-
const constraint = registry.get('no_any_type');
|
|
28
|
-
expect(constraint).toBeDefined();
|
|
29
|
-
expect(constraint?.layer).toBe('quality');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('应该返回 undefined 对于不存在的约束', () => {
|
|
33
|
-
expect(registry.get('nonexistent')).toBeUndefined();
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('getAll', () => {
|
|
38
|
-
it('应该返回所有约束', () => {
|
|
39
|
-
const all = registry.getAll();
|
|
40
|
-
expect(all.length).toBe(SAFETY_COUNT + QUALITY_COUNT);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('getByLayer', () => {
|
|
45
|
-
it('应该按层过滤', () => {
|
|
46
|
-
const safety = registry.getByLayer('safety');
|
|
47
|
-
const quality = registry.getByLayer('quality');
|
|
48
|
-
|
|
49
|
-
expect(safety.every(c => c.layer === 'safety')).toBe(true);
|
|
50
|
-
expect(quality.every(c => c.layer === 'quality')).toBe(true);
|
|
51
|
-
expect(safety.length).toBe(SAFETY_COUNT);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('getByStatus', () => {
|
|
56
|
-
it('应该按退化状态过滤', () => {
|
|
57
|
-
const active = registry.getByStatus('active');
|
|
58
|
-
expect(active.length).toBe(registry.getAll().length);
|
|
59
|
-
|
|
60
|
-
const deprecated = registry.getByStatus('deprecated');
|
|
61
|
-
expect(deprecated.length).toBe(0);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('getByTrigger', () => {
|
|
66
|
-
it('应该按触发条件查找', () => {
|
|
67
|
-
const constraints = registry.getByTrigger('code_implementation');
|
|
68
|
-
expect(constraints.length).toBeGreaterThan(0);
|
|
69
|
-
expect(constraints.every(c => {
|
|
70
|
-
const triggers = Array.isArray(c.trigger) ? c.trigger : [c.trigger];
|
|
71
|
-
return triggers.includes('code_implementation');
|
|
72
|
-
})).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('degrade', () => {
|
|
77
|
-
it('应该降低约束级别', () => {
|
|
78
|
-
const result = registry.degrade('no_any_type');
|
|
79
|
-
expect(result).toBe(true);
|
|
80
|
-
|
|
81
|
-
const constraint = registry.get('no_any_type');
|
|
82
|
-
expect(constraint?.level).toBe('tip');
|
|
83
|
-
expect(constraint?.deprecationStatus).toBe('deprecated');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('安全层约束也可以退化(Iron Law <5% 高阈值)', () => {
|
|
87
|
-
const result = registry.degrade('no_bypass_checkpoint');
|
|
88
|
-
expect(result).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('不应该退化非 active 约束', () => {
|
|
92
|
-
registry.degrade('no_any_type');
|
|
93
|
-
const result = registry.degrade('no_any_type');
|
|
94
|
-
expect(result).toBe(false);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('rollback', () => {
|
|
99
|
-
it('应该回滚退化', () => {
|
|
100
|
-
registry.degrade('no_any_type');
|
|
101
|
-
const result = registry.rollback('no_any_type', 'guideline');
|
|
102
|
-
expect(result).toBe(true);
|
|
103
|
-
|
|
104
|
-
const constraint = registry.get('no_any_type');
|
|
105
|
-
expect(constraint?.level).toBe('guideline');
|
|
106
|
-
expect(constraint?.deprecationStatus).toBe('active');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('不应该回滚不存在的约束', () => {
|
|
110
|
-
const result = registry.rollback('nonexistent', 'guideline');
|
|
111
|
-
expect(result).toBe(false);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('scheduleDeprecation', () => {
|
|
116
|
-
it('应该为质量层约束安排退化', () => {
|
|
117
|
-
const result = registry.scheduleDeprecation('no_skill_without_test', {
|
|
118
|
-
targetLevel: 'tip',
|
|
119
|
-
reason: '测试能力提升',
|
|
120
|
-
rollbackable: true,
|
|
121
|
-
});
|
|
122
|
-
expect(result).toBe(true);
|
|
123
|
-
|
|
124
|
-
const constraint = registry.get('no_skill_without_test');
|
|
125
|
-
expect(constraint?.deprecationStatus).toBe('scheduled');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('不应该为安全层约束安排退化', () => {
|
|
129
|
-
const result = registry.scheduleDeprecation('no_bypass_checkpoint', {
|
|
130
|
-
targetLevel: 'tip',
|
|
131
|
-
reason: 'test',
|
|
132
|
-
rollbackable: true,
|
|
133
|
-
});
|
|
134
|
-
expect(result).toBe(false);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('getLayerStats', () => {
|
|
139
|
-
it('应该返回层统计', () => {
|
|
140
|
-
const stats = registry.getLayerStats();
|
|
141
|
-
expect(stats.length).toBe(2);
|
|
142
|
-
|
|
143
|
-
const safetyStats = stats.find(s => s.layer === 'safety')!;
|
|
144
|
-
expect(safetyStats.totalConstraints).toBe(SAFETY_COUNT);
|
|
145
|
-
expect(safetyStats.active).toBe(safetyStats.totalConstraints);
|
|
146
|
-
|
|
147
|
-
const qualityStats = stats.find(s => s.layer === 'quality')!;
|
|
148
|
-
expect(qualityStats.totalConstraints).toBe(QUALITY_COUNT);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('toLegacyConstraints', () => {
|
|
153
|
-
it('应该转换为旧格式', () => {
|
|
154
|
-
const legacy = registry.toLegacyConstraints();
|
|
155
|
-
expect(legacy.length).toBe(registry.getAll().length);
|
|
156
|
-
expect(legacy[0]).toHaveProperty('id');
|
|
157
|
-
expect(legacy[0]).toHaveProperty('rule');
|
|
158
|
-
expect(legacy[0]).toHaveProperty('level');
|
|
159
|
-
expect(legacy[0]).not.toHaveProperty('layer');
|
|
160
|
-
expect(legacy[0]).not.toHaveProperty('deprecationStatus');
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe('register / remove', () => {
|
|
165
|
-
it('应该注册自定义约束', () => {
|
|
166
|
-
registry.register({
|
|
167
|
-
id: 'custom',
|
|
168
|
-
rule: 'CUSTOM',
|
|
169
|
-
message: '自定义约束',
|
|
170
|
-
level: 'guideline',
|
|
171
|
-
trigger: 'code_implementation',
|
|
172
|
-
enforcement: 'custom-check',
|
|
173
|
-
layer: 'quality',
|
|
174
|
-
deprecationStatus: 'active',
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(registry.get('custom')).toBeDefined();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('应该移除约束', () => {
|
|
181
|
-
registry.register({
|
|
182
|
-
id: 'temp',
|
|
183
|
-
rule: 'TEMP',
|
|
184
|
-
message: '临时',
|
|
185
|
-
level: 'tip',
|
|
186
|
-
trigger: 'commit',
|
|
187
|
-
enforcement: 'temp',
|
|
188
|
-
layer: 'quality',
|
|
189
|
-
deprecationStatus: 'active',
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
expect(registry.remove('temp')).toBe(true);
|
|
193
|
-
expect(registry.get('temp')).toBeUndefined();
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
});
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 约束生命周期执行器
|
|
3
|
-
*
|
|
4
|
-
* 将 ConstraintEvolver 生成的提案转化为 ConstraintRegistry 实际操作。
|
|
5
|
-
* 连接 monitoring 层(proposal)和 constraints 层(registry)。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { ConstraintRegistry } from './registry';
|
|
9
|
-
import type { ConstraintProposal } from '../types/monitoring-types';
|
|
10
|
-
import type { ConstraintLevel } from '../types/constraint';
|
|
11
|
-
import type { DeprecationSchedule } from './types';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 提案执行结果
|
|
15
|
-
*/
|
|
16
|
-
export interface ExecutionResult {
|
|
17
|
-
proposalId: string;
|
|
18
|
-
constraintId: string;
|
|
19
|
-
action: string;
|
|
20
|
-
success: boolean;
|
|
21
|
-
details: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 约束生命周期执行器
|
|
26
|
-
*
|
|
27
|
-
* 将 evolver 的提案(proposal)转化为 registry 的实际操作(degrade/rollback/scheduleDeprecation)
|
|
28
|
-
*/
|
|
29
|
-
export class ConstraintLifecycleRunner {
|
|
30
|
-
private registry: ConstraintRegistry;
|
|
31
|
-
|
|
32
|
-
constructor(registry?: ConstraintRegistry) {
|
|
33
|
-
this.registry = registry || new ConstraintRegistry();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
getRegistry(): ConstraintRegistry {
|
|
37
|
-
return this.registry;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 执行单个已接受的提案
|
|
42
|
-
*/
|
|
43
|
-
execute(proposal: ConstraintProposal): ExecutionResult {
|
|
44
|
-
switch (proposal.type) {
|
|
45
|
-
case 'change_level':
|
|
46
|
-
return this.executeLevelChange(proposal);
|
|
47
|
-
case 'add_exception':
|
|
48
|
-
return this.executeAddException(proposal);
|
|
49
|
-
case 'adjust_trigger':
|
|
50
|
-
return this.executeAdjustTrigger(proposal);
|
|
51
|
-
case 'modify_message':
|
|
52
|
-
return this.executeModifyMessage(proposal);
|
|
53
|
-
default:
|
|
54
|
-
return {
|
|
55
|
-
proposalId: proposal.id,
|
|
56
|
-
constraintId: proposal.constraintId,
|
|
57
|
-
action: proposal.type,
|
|
58
|
-
success: false,
|
|
59
|
-
details: `Unsupported proposal type: ${proposal.type}`,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 批量执行提案
|
|
66
|
-
*/
|
|
67
|
-
executeBatch(proposals: ConstraintProposal[]): ExecutionResult[] {
|
|
68
|
-
return proposals.map(p => this.execute(p));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 回滚已降级的约束
|
|
73
|
-
*/
|
|
74
|
-
rollbackConstraint(constraintId: string, originalLevel: ConstraintLevel): boolean {
|
|
75
|
-
return this.registry.rollback(constraintId, originalLevel);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 设置约束的弃用计划
|
|
80
|
-
*/
|
|
81
|
-
scheduleDeprecation(constraintId: string, schedule: DeprecationSchedule): boolean {
|
|
82
|
-
return this.registry.scheduleDeprecation(constraintId, schedule);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
private executeLevelChange(proposal: ConstraintProposal): ExecutionResult {
|
|
86
|
-
const constraint = this.registry.get(proposal.constraintId);
|
|
87
|
-
if (!constraint) {
|
|
88
|
-
return this.failResult(proposal, `Constraint ${proposal.constraintId} not found`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (constraint.layer === 'safety') {
|
|
92
|
-
return this.failResult(proposal, 'Cannot change level of safety-layer constraint');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const targetLevel = proposal.content.proposed as ConstraintLevel;
|
|
96
|
-
const currentLevel = constraint.level;
|
|
97
|
-
|
|
98
|
-
const levelOrder: Record<string, number> = { iron_law: 0, guideline: 1, tip: 2 };
|
|
99
|
-
if ((levelOrder[targetLevel] ?? 99) > (levelOrder[currentLevel] ?? 0)) {
|
|
100
|
-
const success = this.registry.degrade(proposal.constraintId);
|
|
101
|
-
return {
|
|
102
|
-
proposalId: proposal.id,
|
|
103
|
-
constraintId: proposal.constraintId,
|
|
104
|
-
action: 'degrade',
|
|
105
|
-
success,
|
|
106
|
-
details: success
|
|
107
|
-
? `Degraded from ${currentLevel} to ${targetLevel}`
|
|
108
|
-
: 'Degradation failed',
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return this.failResult(proposal, 'Level change direction not supported via registry');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private executeAddException(proposal: ConstraintProposal): ExecutionResult {
|
|
116
|
-
const constraint = this.registry.get(proposal.constraintId);
|
|
117
|
-
if (!constraint) {
|
|
118
|
-
return this.failResult(proposal, `Constraint ${proposal.constraintId} not found`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const exception = proposal.content.proposed;
|
|
122
|
-
const currentExceptions = constraint.exceptions || [];
|
|
123
|
-
|
|
124
|
-
if (currentExceptions.includes(exception)) {
|
|
125
|
-
return this.failResult(proposal, `Exception ${exception} already exists`);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!constraint.exceptions) constraint.exceptions = [];
|
|
129
|
-
constraint.exceptions.push(exception);
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
proposalId: proposal.id,
|
|
133
|
-
constraintId: proposal.constraintId,
|
|
134
|
-
action: 'add_exception',
|
|
135
|
-
success: true,
|
|
136
|
-
details: `Added exception: ${exception}`,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private executeAdjustTrigger(proposal: ConstraintProposal): ExecutionResult {
|
|
141
|
-
const constraint = this.registry.get(proposal.constraintId);
|
|
142
|
-
if (!constraint) {
|
|
143
|
-
return this.failResult(proposal, `Constraint ${proposal.constraintId} not found`);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const oldTrigger = constraint.trigger;
|
|
147
|
-
constraint.trigger = proposal.content.proposed;
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
proposalId: proposal.id,
|
|
151
|
-
constraintId: proposal.constraintId,
|
|
152
|
-
action: 'adjust_trigger',
|
|
153
|
-
success: true,
|
|
154
|
-
details: `Changed trigger from ${JSON.stringify(oldTrigger)} to ${JSON.stringify(proposal.content.proposed)}`,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private executeModifyMessage(proposal: ConstraintProposal): ExecutionResult {
|
|
159
|
-
const constraint = this.registry.get(proposal.constraintId);
|
|
160
|
-
if (!constraint) {
|
|
161
|
-
return this.failResult(proposal, `Constraint ${proposal.constraintId} not found`);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
constraint.message = proposal.content.proposed;
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
proposalId: proposal.id,
|
|
168
|
-
constraintId: proposal.constraintId,
|
|
169
|
-
action: 'modify_message',
|
|
170
|
-
success: true,
|
|
171
|
-
details: 'Updated message',
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
private failResult(proposal: ConstraintProposal, details: string): ExecutionResult {
|
|
176
|
-
return {
|
|
177
|
-
proposalId: proposal.id,
|
|
178
|
-
constraintId: proposal.constraintId,
|
|
179
|
-
action: proposal.type,
|
|
180
|
-
success: false,
|
|
181
|
-
details,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
}
|