@principles/pd-cli 1.82.0 → 1.84.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/diagnose.d.ts.map +1 -1
- package/dist/commands/diagnose.js +5 -0
- package/dist/commands/diagnose.js.map +1 -1
- package/dist/commands/pain-retry.d.ts.map +1 -1
- package/dist/commands/pain-retry.js +5 -0
- package/dist/commands/pain-retry.js.map +1 -1
- package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/dist/commands/runtime-internalization-run-once.js +5 -1
- package/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/dist/commands/runtime-uat.d.ts +1 -0
- package/dist/commands/runtime-uat.d.ts.map +1 -1
- package/dist/commands/runtime-uat.guard.test.d.ts +2 -0
- package/dist/commands/runtime-uat.guard.test.d.ts.map +1 -0
- package/dist/commands/runtime-uat.guard.test.js +155 -0
- package/dist/commands/runtime-uat.guard.test.js.map +1 -0
- package/dist/commands/runtime-uat.js +29 -3
- package/dist/commands/runtime-uat.js.map +1 -1
- package/dist/config-reader.d.ts +25 -0
- package/dist/config-reader.d.ts.map +1 -0
- package/dist/config-reader.js +109 -0
- package/dist/config-reader.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/production-workspace-guard.d.ts +77 -0
- package/dist/utils/production-workspace-guard.d.ts.map +1 -0
- package/dist/utils/production-workspace-guard.js +170 -0
- package/dist/utils/production-workspace-guard.js.map +1 -0
- package/dist/utils/production-workspace-guard.test.d.ts +2 -0
- package/dist/utils/production-workspace-guard.test.d.ts.map +1 -0
- package/dist/utils/production-workspace-guard.test.js +95 -0
- package/dist/utils/production-workspace-guard.test.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/diagnose.ts +8 -1
- package/src/commands/pain-retry.ts +8 -1
- package/src/commands/runtime-internalization-run-once.ts +6 -2
- package/src/commands/runtime-uat.guard.test.ts +177 -0
- package/src/commands/runtime-uat.ts +42 -4
- package/src/config-reader.ts +122 -0
- package/src/index.ts +2 -0
- package/src/utils/production-workspace-guard.test.ts +108 -0
- package/src/utils/production-workspace-guard.ts +219 -0
- package/tests/commands/candidate-audit-repair.test.ts +1 -0
- package/tests/commands/candidate-intake.test.ts +1 -0
- package/tests/commands/candidate-internalization-backfill.test.ts +1 -0
- package/tests/commands/candidate-internalize.test.ts +1 -0
- package/tests/commands/candidate-route.test.ts +1 -0
- package/tests/commands/diagnose.test.ts +5 -0
- package/tests/commands/health.test.ts +1 -0
- package/tests/commands/pain-record.test.ts +1 -0
- package/tests/commands/pain-retry.test.ts +5 -0
- package/tests/commands/runtime-activation.test.ts +1 -0
- package/tests/commands/runtime-canary.test.ts +1 -0
- package/tests/commands/runtime-diagnostics-export.test.ts +1 -0
- package/tests/commands/runtime-health-snapshot.test.ts +1 -0
- package/tests/commands/runtime-internalization-enqueue-successors.test.ts +1 -0
- package/tests/commands/runtime-internalization-integrity-repair.test.ts +1 -0
- package/tests/commands/runtime-internalization-integrity.test.ts +1 -0
- package/tests/commands/runtime-internalization-queue.test.ts +1 -0
- package/tests/commands/runtime-internalization-run-once.test.ts +5 -0
- package/tests/commands/runtime-internalization-wake-once.test.ts +1 -0
- package/tests/commands/runtime-pruning.test.ts +1 -0
- package/tests/commands/runtime-recovery.test.ts +1 -0
- package/tests/commands/runtime.test.ts +1 -0
- package/tests/commands/trace.test.ts +1 -0
- package/tests/config-reader.test.ts +142 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production Workspace Guard
|
|
3
|
+
*
|
|
4
|
+
* Prevents UAT/runtime test commands from writing to production workspaces.
|
|
5
|
+
*
|
|
6
|
+
* Production workspaces are:
|
|
7
|
+
* - D:\.openclaw\workspace
|
|
8
|
+
* - C:\Users\Administrator\.openclaw\workspace
|
|
9
|
+
* - And the default workspace resolved by OpenClaw configuration
|
|
10
|
+
*
|
|
11
|
+
* This module follows ERR-030 (path prefix matching must use segment boundaries)
|
|
12
|
+
* and EP-03/EP-04 (fail loud with structured reason and nextAction).
|
|
13
|
+
*/
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
import * as os from 'os';
|
|
16
|
+
import { existsSync } from 'fs';
|
|
17
|
+
// ── Production workspace paths ─────────────────────────────────────────────────
|
|
18
|
+
/**
|
|
19
|
+
* List of production workspace paths that should be protected from UAT/test writes.
|
|
20
|
+
* These are the default paths where PD is typically installed and used for real work.
|
|
21
|
+
*/
|
|
22
|
+
const PRODUCTION_WORKSPACE_PATHS = [
|
|
23
|
+
// Windows default
|
|
24
|
+
path.resolve('D:\\.openclaw\\workspace'),
|
|
25
|
+
path.resolve('C:\\.openclaw\\workspace'),
|
|
26
|
+
path.resolve('C:\\Users\\Administrator\\.openclaw\\workspace'),
|
|
27
|
+
path.resolve('C:\\Users\\Admin\\.openclaw\\workspace'),
|
|
28
|
+
// Unix-like defaults
|
|
29
|
+
path.resolve(path.join(os.homedir(), '.openclaw', 'workspace')),
|
|
30
|
+
// macOS-specific
|
|
31
|
+
path.resolve(path.join(os.homedir(), '.openclaw', 'workspace')),
|
|
32
|
+
];
|
|
33
|
+
// ── Resolution helpers ───────────────────────────────────────────────────────
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the workspace path from environment variable or current directory.
|
|
36
|
+
*/
|
|
37
|
+
export function resolveWorkspacePath(inputPath) {
|
|
38
|
+
if (!inputPath) {
|
|
39
|
+
// Default to current directory
|
|
40
|
+
return path.resolve(process.cwd());
|
|
41
|
+
}
|
|
42
|
+
return path.resolve(inputPath);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if a path is a production workspace.
|
|
46
|
+
*
|
|
47
|
+
* This follows ERR-030: path matching must use segment boundaries (path.sep)
|
|
48
|
+
* to avoid false positives on sibling directories like "workspace-backup".
|
|
49
|
+
*
|
|
50
|
+
* @param resolvedPath - The absolute, normalized workspace path to check
|
|
51
|
+
* @returns true if the path is a production workspace
|
|
52
|
+
*/
|
|
53
|
+
export function isProductionWorkspace(resolvedPath) {
|
|
54
|
+
const normalized = resolvedPath.toLowerCase();
|
|
55
|
+
for (const prodPath of PRODUCTION_WORKSPACE_PATHS) {
|
|
56
|
+
const normalizedProd = prodPath.toLowerCase();
|
|
57
|
+
// Exact match
|
|
58
|
+
if (normalized === normalizedProd) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
// Descendant match: must have path separator after prefix
|
|
62
|
+
// ERR-030: "startsWith" without separator matches sibling directories
|
|
63
|
+
if (normalized.startsWith(normalizedProd + path.sep)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
// Handle Windows path variations
|
|
67
|
+
// D:\.openclaw\workspace should not match D:\.openclaw\workspace-backup
|
|
68
|
+
// Use case-insensitive comparison (already normalized)
|
|
69
|
+
if (path.sep === '\\') {
|
|
70
|
+
// Windows: check both forward and backslash
|
|
71
|
+
if (normalized.startsWith(normalizedProd + '/')) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (normalized.startsWith(normalizedProd.replace(/\\/g, '/') + '/')) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (normalized.startsWith(normalizedProd.replace(/\\/g, '/') + '\\')) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if a workspace is protected from UAT/test writes.
|
|
86
|
+
*
|
|
87
|
+
* This is the main guard function for UAT/runtime test commands.
|
|
88
|
+
* It returns a structured result following EP-03/EP-04 requirements.
|
|
89
|
+
*
|
|
90
|
+
* @param inputPath - The workspace path to check (optional, resolves to cwd if not provided)
|
|
91
|
+
* @param commandContext - Context string for the error message (e.g., "pd runtime uat")
|
|
92
|
+
* @returns GuardResult indicating if the operation is allowed or refused
|
|
93
|
+
*/
|
|
94
|
+
export function guardUatWorkspace(inputPath, _commandContext) {
|
|
95
|
+
const resolved = resolveWorkspacePath(inputPath);
|
|
96
|
+
// PRI-334: Guard check should happen BEFORE file existence check
|
|
97
|
+
// This prevents production workspace writes even if directory doesn't exist yet
|
|
98
|
+
if (isProductionWorkspace(resolved)) {
|
|
99
|
+
return {
|
|
100
|
+
refused: true,
|
|
101
|
+
workspace: resolved,
|
|
102
|
+
isProduction: true,
|
|
103
|
+
reason: `UAT/runtime test commands are not allowed to write to the production workspace (${resolved}). This prevents test/synthetic data from polluting your real PD state.`,
|
|
104
|
+
nextAction: `Use a temporary workspace for testing (recommended: ${os.tmpdir()}/pd-uat-workspace) or explicitly confirm you understand the risk by using --allow-production-workspace-for-uat (not recommended).`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (!existsSync(resolved)) {
|
|
108
|
+
// Non-existent workspace is safe to use (will be created)
|
|
109
|
+
return {
|
|
110
|
+
refused: false,
|
|
111
|
+
workspace: resolved,
|
|
112
|
+
isProduction: false,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
refused: false,
|
|
117
|
+
workspace: resolved,
|
|
118
|
+
isProduction: false,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get a safe UAT workspace path in the system temp directory.
|
|
123
|
+
*
|
|
124
|
+
* This follows the safe execution path requirement from PRI-334.
|
|
125
|
+
*/
|
|
126
|
+
export function getSafeUatWorkspacePath() {
|
|
127
|
+
const tempDir = os.tmpdir();
|
|
128
|
+
// Create a unique but deterministic path for UAT workspaces
|
|
129
|
+
const uatWorkspace = path.join(tempDir, 'pd-uat-workspace');
|
|
130
|
+
return uatWorkspace;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if --allow-production-workspace-for-uat flag is set.
|
|
134
|
+
*
|
|
135
|
+
* This is the escape hatch for cases where the operator explicitly wants to run UAT on production.
|
|
136
|
+
* The flag must be very explicit in both name and output (as required by PRI-334).
|
|
137
|
+
*/
|
|
138
|
+
export function isProductionWorkspaceAllowed() {
|
|
139
|
+
// Check if the flag was parsed and passed through opts
|
|
140
|
+
// This will be called from command handlers after Commander parses flags
|
|
141
|
+
return false; // Placeholder; actual check depends on Commander opts
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Format guard refusal for console output.
|
|
145
|
+
*
|
|
146
|
+
* Follows EP-03/EP-04: structured reason + nextAction.
|
|
147
|
+
*/
|
|
148
|
+
export function formatGuardRefusal(refusal, commandContext, jsonMode = false) {
|
|
149
|
+
if (jsonMode) {
|
|
150
|
+
// JSON mode: output exactly one JSON object with reason and nextAction
|
|
151
|
+
return JSON.stringify({
|
|
152
|
+
status: 'refused',
|
|
153
|
+
reason: refusal.reason,
|
|
154
|
+
nextAction: refusal.nextAction,
|
|
155
|
+
workspace: refusal.workspace,
|
|
156
|
+
isProduction: refusal.isProduction,
|
|
157
|
+
}, null, 2);
|
|
158
|
+
}
|
|
159
|
+
// Text mode: human-readable structured output
|
|
160
|
+
return [
|
|
161
|
+
`[pd-cli] ERROR: ${commandContext} - workspace guard triggered`,
|
|
162
|
+
'',
|
|
163
|
+
`Reason: ${refusal.reason}`,
|
|
164
|
+
`Next Action: ${refusal.nextAction}`,
|
|
165
|
+
`Workspace: ${refusal.workspace}`,
|
|
166
|
+
'',
|
|
167
|
+
'This guard prevents UAT/runtime test data from polluting your production workspace.',
|
|
168
|
+
].join('\n');
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=production-workspace-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"production-workspace-guard.js","sourceRoot":"","sources":["../../src/utils/production-workspace-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,kFAAkF;AAElF;;;GAGG;AACH,MAAM,0BAA0B,G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;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,OAAO,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;IAC5B,4DAA4D;IAC5D,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAC5D,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B;IAC1C,uDAAuD;IACvD,yEAAyE;IACzE,OAAO,KAAK,CAAC,CAAC,sDAAsD;AACtE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAqB,EAAE,cAAsB,EAAE,QAAQ,GAAG,KAAK;IAChG,IAAI,QAAQ,EAAE,CAAC;QACb,uEAAuE;QACvE,OAAO,IAAI,CAAC,SAAS,CACnB;YACE,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,YAAY,EAAE,OAAO,CAAC,YAAY;SACnC,EACD,IAAI,EACJ,CAAC,CACF,CAAC;IACJ,CAAC;IAED,8CAA8C;IAC9C,OAAO;QACL,mBAAmB,cAAc,8BAA8B;QAC/D,EAAE;QACF,WAAW,OAAO,CAAC,MAAM,EAAE;QAC3B,gBAAgB,OAAO,CAAC,UAAU,EAAE;QACpC,cAAc,OAAO,CAAC,SAAS,EAAE;QACjC,EAAE;QACF,qFAAqF;KACtF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"production-workspace-guard.test.d.ts","sourceRoot":"","sources":["../../src/utils/production-workspace-guard.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import { isProductionWorkspace, guardUatWorkspace, getSafeUatWorkspacePath, formatGuardRefusal, } from './production-workspace-guard.js';
|
|
5
|
+
const PRODUCTION_PATHS = [
|
|
6
|
+
'D:\\.openclaw\\workspace',
|
|
7
|
+
'C:\\.openclaw\\workspace',
|
|
8
|
+
'C:\\Users\\Administrator\\.openclaw\\workspace',
|
|
9
|
+
path.join(os.homedir(), '.openclaw', 'workspace'),
|
|
10
|
+
];
|
|
11
|
+
const SAFE_PATHS = [
|
|
12
|
+
'D:\\.openclaw\\workspace-test',
|
|
13
|
+
'D:\\.openclaw\\workspace-backup',
|
|
14
|
+
path.join(os.tmpdir(), 'pd-uat-workspace'),
|
|
15
|
+
path.join(os.tmpdir(), 'pd-test-any'),
|
|
16
|
+
'C:\\completely-unrelated\\work',
|
|
17
|
+
];
|
|
18
|
+
describe('isProductionWorkspace', () => {
|
|
19
|
+
it.each(PRODUCTION_PATHS)('detects production: %s', (prodPath) => {
|
|
20
|
+
expect(isProductionWorkspace(path.resolve(prodPath))).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
it.each(SAFE_PATHS)('allows safe: %s', (safePath) => {
|
|
23
|
+
expect(isProductionWorkspace(path.resolve(safePath))).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
it('detects descendant', () => {
|
|
26
|
+
expect(isProductionWorkspace(path.resolve('D:\\.openclaw\\workspace\\sub\\child'))).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('rejects sibling workspace-test (ERR-030)', () => {
|
|
29
|
+
expect(isProductionWorkspace(path.resolve('D:\\.openclaw\\workspace-test'))).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
it('rejects sibling workspace-backup (ERR-030)', () => {
|
|
32
|
+
expect(isProductionWorkspace(path.resolve('D:\\.openclaw\\workspace-backup'))).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('guardUatWorkspace', () => {
|
|
36
|
+
describe('refused', () => {
|
|
37
|
+
it.each(PRODUCTION_PATHS)('refuses production: %s', (prodPath) => {
|
|
38
|
+
const r = guardUatWorkspace(prodPath, 'test');
|
|
39
|
+
expect(r.refused).toBe(true);
|
|
40
|
+
if (r.refused) {
|
|
41
|
+
expect(r.reason).toContain('UAT/runtime test commands are not allowed');
|
|
42
|
+
expect(r.nextAction).toContain('temporary workspace');
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
it('refuses descendant', () => {
|
|
46
|
+
expect(guardUatWorkspace('D:\\.openclaw\\workspace\\subdir', 'test').refused).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('allowed', () => {
|
|
50
|
+
it.each(SAFE_PATHS)('allows safe: %s', (safePath) => {
|
|
51
|
+
const r = guardUatWorkspace(safePath, 'test');
|
|
52
|
+
expect(r.refused).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
it.each(['D:\\.openclaw\\workspace-test', 'D:\\.openclaw\\workspace-backup'])('allows sibling: %s (ERR-030)', (p) => {
|
|
55
|
+
expect(guardUatWorkspace(p, 'test').refused).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('JSON output (EP-04)', () => {
|
|
60
|
+
it('outputs single object with reason and nextAction', () => {
|
|
61
|
+
const r = guardUatWorkspace('D:\\.openclaw\\workspace', 'test');
|
|
62
|
+
const json = formatGuardRefusal(r, 'test', true);
|
|
63
|
+
const parsed = JSON.parse(json);
|
|
64
|
+
expect(parsed).toMatchObject({
|
|
65
|
+
status: 'refused', reason: expect.any(String), nextAction: expect.any(String),
|
|
66
|
+
workspace: expect.any(String), isProduction: true,
|
|
67
|
+
});
|
|
68
|
+
expect(Array.isArray(parsed)).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
it('no console prefixes in JSON', () => {
|
|
71
|
+
const r = guardUatWorkspace('D:\\.openclaw\\workspace', 'test');
|
|
72
|
+
const json = formatGuardRefusal(r, 'test', true);
|
|
73
|
+
expect(json).not.toContain('[pd-cli]');
|
|
74
|
+
expect(json).not.toContain('ERROR:');
|
|
75
|
+
expect(json.trim().startsWith('{')).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('text output (EP-03)', () => {
|
|
79
|
+
it('includes reason and nextAction', () => {
|
|
80
|
+
const r = guardUatWorkspace('D:\\.openclaw\\workspace', 'test');
|
|
81
|
+
const text = formatGuardRefusal(r, 'test', false);
|
|
82
|
+
expect(text).toContain('Reason:');
|
|
83
|
+
expect(text).toContain('Next Action:');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe('getSafeUatWorkspacePath', () => {
|
|
87
|
+
it('returns deterministic temp path', () => {
|
|
88
|
+
const p1 = getSafeUatWorkspacePath();
|
|
89
|
+
const p2 = getSafeUatWorkspacePath();
|
|
90
|
+
expect(p1).toBe(p2);
|
|
91
|
+
expect(p1).toContain(os.tmpdir());
|
|
92
|
+
expect(p1).toContain('pd-uat-workspace');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=production-workspace-guard.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"production-workspace-guard.test.js","sourceRoot":"","sources":["../../src/utils/production-workspace-guard.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,GAEnB,MAAM,iCAAiC,CAAC;AAEzC,MAAM,gBAAgB,GAAG;IACvB,0BAA0B;IAC1B,0BAA0B;IAC1B,gDAAgD;IAChD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,WAAW,CAAC;CAClD,CAAC;AAEF,MA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core/runtime-v2';
|
|
29
|
-
import type { PDRuntimeAdapter, RuntimeConfig } from '@principles/core/runtime-v2';
|
|
29
|
+
import type { PDRuntimeAdapter, RuntimeConfig, OutputLanguage } from '@principles/core/runtime-v2';
|
|
30
30
|
import { PrincipleTreeLedgerAdapter } from '../principle-tree-ledger-adapter.js';
|
|
31
31
|
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
32
|
+
import { readOutputLanguageFromWorkspace } from '../config-reader.js';
|
|
32
33
|
import * as path from 'path';
|
|
33
34
|
|
|
34
35
|
interface DiagnoseStatusOptions {
|
|
@@ -281,6 +282,11 @@ export async function handleDiagnoseRun(opts: DiagnoseRunOptions): Promise<void>
|
|
|
281
282
|
|
|
282
283
|
const eventEmitter = new StoreEventEmitter();
|
|
283
284
|
const committer = new SqliteDiagnosticianCommitter(sqliteConn);
|
|
285
|
+
|
|
286
|
+
// PRI-336: Read outputLanguage from workspace config
|
|
287
|
+
const outputLangResult = readOutputLanguageFromWorkspace(workspaceDir);
|
|
288
|
+
const outputLanguage: OutputLanguage | undefined = outputLangResult.outputLanguage;
|
|
289
|
+
|
|
284
290
|
const runner = new DiagnosticianRunner(
|
|
285
291
|
{
|
|
286
292
|
stateManager,
|
|
@@ -296,6 +302,7 @@ export async function handleDiagnoseRun(opts: DiagnoseRunOptions): Promise<void>
|
|
|
296
302
|
pollIntervalMs: 100,
|
|
297
303
|
timeoutMs: 300_000, // 5 min — same as probe timeout for real LLM calls
|
|
298
304
|
agentId: opts.agent,
|
|
305
|
+
outputLanguage,
|
|
299
306
|
},
|
|
300
307
|
);
|
|
301
308
|
|
|
@@ -29,9 +29,10 @@ import {
|
|
|
29
29
|
CandidateIntakeService,
|
|
30
30
|
run as diagnoseRun,
|
|
31
31
|
} from '@principles/core/runtime-v2';
|
|
32
|
-
import type { PDRuntimeAdapter, RuntimeConfig } from '@principles/core/runtime-v2';
|
|
32
|
+
import type { PDRuntimeAdapter, RuntimeConfig, OutputLanguage } from '@principles/core/runtime-v2';
|
|
33
33
|
import type { PDTaskStatus } from '@principles/core/runtime-v2';
|
|
34
34
|
import { PrincipleTreeLedgerAdapter } from '../principle-tree-ledger-adapter.js';
|
|
35
|
+
import { readOutputLanguageFromWorkspace } from '../config-reader.js';
|
|
35
36
|
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
36
37
|
import * as path from 'path';
|
|
37
38
|
|
|
@@ -362,6 +363,11 @@ export async function handlePainRetry(opts: PainRetryOptions): Promise<void> {
|
|
|
362
363
|
|
|
363
364
|
const eventEmitter = new StoreEventEmitter();
|
|
364
365
|
const committer = new SqliteDiagnosticianCommitter(sqliteConn);
|
|
366
|
+
|
|
367
|
+
// PRI-336: Read outputLanguage from workspace config
|
|
368
|
+
const outputLangResult = readOutputLanguageFromWorkspace(workspaceDir);
|
|
369
|
+
const outputLanguage: OutputLanguage | undefined = outputLangResult.outputLanguage;
|
|
370
|
+
|
|
365
371
|
const runner = new DiagnosticianRunner(
|
|
366
372
|
{
|
|
367
373
|
stateManager,
|
|
@@ -377,6 +383,7 @@ export async function handlePainRetry(opts: PainRetryOptions): Promise<void> {
|
|
|
377
383
|
pollIntervalMs: 100,
|
|
378
384
|
timeoutMs: 300_000,
|
|
379
385
|
agentId: opts.agent,
|
|
386
|
+
outputLanguage,
|
|
380
387
|
},
|
|
381
388
|
);
|
|
382
389
|
|
|
@@ -24,8 +24,9 @@ import {
|
|
|
24
24
|
isRuntimeConfigError,
|
|
25
25
|
validateRuntimeConfig,
|
|
26
26
|
} from '@principles/core/runtime-v2';
|
|
27
|
-
import type { WakeOnceResult, DreamerRunnerResult, PhilosopherRunnerResult, ScribeRunnerResult, ArtificerRunnerResult, EvaluatorRunnerResult, RolloutReviewerRunnerResult, TrainerRunnerResult, PDRuntimeAdapter, PeerRunnerKind } from '@principles/core/runtime-v2';
|
|
27
|
+
import type { WakeOnceResult, DreamerRunnerResult, PhilosopherRunnerResult, ScribeRunnerResult, ArtificerRunnerResult, EvaluatorRunnerResult, RolloutReviewerRunnerResult, TrainerRunnerResult, PDRuntimeAdapter, PeerRunnerKind, OutputLanguage } from '@principles/core/runtime-v2';
|
|
28
28
|
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
29
|
+
import { readOutputLanguageFromWorkspace } from '../config-reader.js';
|
|
29
30
|
|
|
30
31
|
interface RunOnceOptions {
|
|
31
32
|
workspace?: string;
|
|
@@ -589,10 +590,13 @@ export async function handleRuntimeInternalizationRunOnce(opts: RunOnceOptions):
|
|
|
589
590
|
);
|
|
590
591
|
runnerResult = await runner.run(wakeResult.taskId);
|
|
591
592
|
} else if (runnerKind === 'scribe') {
|
|
593
|
+
// PRI-336: Read outputLanguage from workspace config
|
|
594
|
+
const outputLangResult = readOutputLanguageFromWorkspace(workspaceDir);
|
|
595
|
+
const outputLanguage: OutputLanguage | undefined = outputLangResult.outputLanguage;
|
|
592
596
|
const validator = new DefaultScribeValidator();
|
|
593
597
|
const runner = new ScribeRunner(
|
|
594
598
|
{ stateManager, runtimeAdapter, eventEmitter, validator, artifactStore },
|
|
595
|
-
{ owner: OWNER, runtimeKind: RUNTIME_KIND, pollIntervalMs: 100, timeoutMs: effectiveTimeoutMs },
|
|
599
|
+
{ owner: OWNER, runtimeKind: RUNTIME_KIND, pollIntervalMs: 100, timeoutMs: effectiveTimeoutMs, outputLanguage },
|
|
596
600
|
);
|
|
597
601
|
runnerResult = await runner.run(wakeResult.taskId);
|
|
598
602
|
} else if (runnerKind === 'artificer') {
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-334: Runtime UAT guard — command-level integration tests.
|
|
3
|
+
*
|
|
4
|
+
* These tests verify the guard is wired into the real Commander command
|
|
5
|
+
* and that refused paths do NOT call execFileSync (mutation prevention).
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, vi, beforeEach, afterAll, beforeAll } from 'vitest';
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import * as os from 'os';
|
|
11
|
+
|
|
12
|
+
// ─── Mocks ─────────────────────────────────────────────────────────────────
|
|
13
|
+
const mockExecFileSync = vi.fn();
|
|
14
|
+
vi.mock('child_process', () => ({
|
|
15
|
+
execFileSync: mockExecFileSync,
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const { handleRuntimeUat } = await import('./runtime-uat.js');
|
|
19
|
+
const { guardUatWorkspace } = await import('../utils/production-workspace-guard.js');
|
|
20
|
+
|
|
21
|
+
// ─── Test Setup ─────────────────────────────────────────────────────────────
|
|
22
|
+
const capturedStderr: string[] = [];
|
|
23
|
+
const capturedStdout: string[] = [];
|
|
24
|
+
let capturedExitCode: number | null = null;
|
|
25
|
+
|
|
26
|
+
const originalExit = process.exit;
|
|
27
|
+
const originalError = console.error;
|
|
28
|
+
const originalLog = console.log;
|
|
29
|
+
const originalEnv = { ...process.env };
|
|
30
|
+
|
|
31
|
+
beforeAll(() => {
|
|
32
|
+
process.exit = vi.fn(((code?: number) => {
|
|
33
|
+
capturedExitCode = code ?? 0;
|
|
34
|
+
}) as typeof process.exit);
|
|
35
|
+
console.error = vi.fn((...args: unknown[]) => { capturedStderr.push(args.join(' ')); });
|
|
36
|
+
console.log = vi.fn((...args: unknown[]) => { capturedStdout.push(args.join(' ')); });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
process.exit = originalExit;
|
|
41
|
+
console.error = originalError;
|
|
42
|
+
console.log = originalLog;
|
|
43
|
+
process.env = originalEnv;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
capturedExitCode = null;
|
|
48
|
+
capturedStderr.length = 0;
|
|
49
|
+
capturedStdout.length = 0;
|
|
50
|
+
mockExecFileSync.mockReset();
|
|
51
|
+
process.env = { ...process.env, MINIMAX_CN_API_KEY: 'test-key-for-pri-334' };
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// ─── Tests ──────────────────────────────────────────────────────────────────
|
|
55
|
+
describe('PRI-334: production workspace refusal', () => {
|
|
56
|
+
it('refuses D: workspace with exit code 1', async () => {
|
|
57
|
+
mockExecFileSync.mockClear();
|
|
58
|
+
await handleRuntimeUat({ workspace: 'D:\\.openclaw\\workspace', count: 1 });
|
|
59
|
+
expect(capturedExitCode).toBe(1);
|
|
60
|
+
expect(mockExecFileSync).not.toHaveBeenCalled();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('refuses C: workspace with exit code 1', async () => {
|
|
64
|
+
mockExecFileSync.mockClear();
|
|
65
|
+
await handleRuntimeUat({ workspace: 'C:\\.openclaw\\workspace', count: 1 });
|
|
66
|
+
expect(capturedExitCode).toBe(1);
|
|
67
|
+
expect(mockExecFileSync).not.toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('refuses production workspace subdirectory', async () => {
|
|
71
|
+
mockExecFileSync.mockClear();
|
|
72
|
+
await handleRuntimeUat({ workspace: 'D:\\.openclaw\\workspace\\sub\\path', count: 1 });
|
|
73
|
+
expect(capturedExitCode).toBe(1);
|
|
74
|
+
expect(mockExecFileSync).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('PRI-334: allowed paths (guard level)', () => {
|
|
79
|
+
it('allows temp workspace', () => {
|
|
80
|
+
const tempPath = path.join(os.tmpdir(), 'pd-test-' + Date.now());
|
|
81
|
+
expect(guardUatWorkspace(tempPath, 'test').refused).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('allows workspace-test sibling (ERR-030)', () => {
|
|
85
|
+
expect(guardUatWorkspace('D:\\.openclaw\\workspace-test', 'test').refused).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('allows workspace-backup sibling (ERR-030)', () => {
|
|
89
|
+
expect(guardUatWorkspace('D:\\.openclaw\\workspace-backup', 'test').refused).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('PRI-334: JSON output (EP-04)', () => {
|
|
94
|
+
it('outputs single JSON object with reason and nextAction', async () => {
|
|
95
|
+
mockExecFileSync.mockClear();
|
|
96
|
+
capturedStdout.length = 0;
|
|
97
|
+
await handleRuntimeUat({ workspace: 'D:\\.openclaw\\workspace', count: 1, json: true });
|
|
98
|
+
expect(capturedExitCode).toBe(1);
|
|
99
|
+
expect(mockExecFileSync).not.toHaveBeenCalled();
|
|
100
|
+
|
|
101
|
+
const jsonOutput = capturedStdout.join('');
|
|
102
|
+
const parsed = JSON.parse(jsonOutput);
|
|
103
|
+
expect(parsed).toMatchObject({
|
|
104
|
+
status: 'refused', reason: expect.any(String), nextAction: expect.any(String),
|
|
105
|
+
workspace: expect.any(String), isProduction: true,
|
|
106
|
+
});
|
|
107
|
+
expect(Array.isArray(parsed)).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('PRI-334: escape hatch', () => {
|
|
112
|
+
it('warns when allow-production-workspace-for-uat flag is set', async () => {
|
|
113
|
+
mockExecFileSync.mockClear();
|
|
114
|
+
mockExecFileSync.mockImplementation(() => '{"painId":"test","taskId":"t1","runId":"r1","candidateIds":["c1"],"ledgerEntryIds":["l1"]}');
|
|
115
|
+
capturedStderr.length = 0;
|
|
116
|
+
capturedExitCode = null;
|
|
117
|
+
|
|
118
|
+
await handleRuntimeUat({ workspace: 'D:\\.openclaw\\workspace', count: 1, allowProductionWorkspaceForUat: true });
|
|
119
|
+
const stderrText = capturedStderr.join('\n');
|
|
120
|
+
expect(stderrText).toContain('WARNING');
|
|
121
|
+
expect(stderrText).toContain('--allow-production-workspace-for-uat');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('PRI-334: mutation prevention', () => {
|
|
126
|
+
it('does not call execFileSync after guard refusal', async () => {
|
|
127
|
+
mockExecFileSync.mockClear();
|
|
128
|
+
await handleRuntimeUat({ workspace: 'D:\\.openclaw\\workspace', count: 1 });
|
|
129
|
+
expect(mockExecFileSync).not.toHaveBeenCalled();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('PRI-334: Commander flag wiring (ERR-063)', () => {
|
|
134
|
+
it('parses --allow-production-workspace-for-uat', () => {
|
|
135
|
+
const program = new Command();
|
|
136
|
+
const rt = program.command('runtime');
|
|
137
|
+
rt.command('uat')
|
|
138
|
+
.option('--allow-production-workspace-for-uat', 'Escape hatch')
|
|
139
|
+
.action(() => { /* noop */ });
|
|
140
|
+
const cmd = rt.commands.find((c) => c.name() === 'uat') as Command;
|
|
141
|
+
const opt = cmd.options.find((o) => o.long === '--allow-production-workspace-for-uat');
|
|
142
|
+
expect(opt).toBeDefined();
|
|
143
|
+
expect(opt?.long).toBe('--allow-production-workspace-for-uat');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('negated form is NOT registered', () => {
|
|
147
|
+
const program = new Command();
|
|
148
|
+
const rt = program.command('runtime');
|
|
149
|
+
rt.command('uat')
|
|
150
|
+
.option('--allow-production-workspace-for-uat', 'Escape hatch')
|
|
151
|
+
.action(() => { /* noop */ });
|
|
152
|
+
const cmd = rt.commands.find((c) => c.name() === 'uat') as Command;
|
|
153
|
+
const noForm = cmd.options.find((o) => o.long === '--no-allow-production-workspace-for-uat');
|
|
154
|
+
expect(noForm).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('PRI-334: shouldExitWithError exit path (EP-04)', () => {
|
|
159
|
+
it('exits 1 and does not print ALL CHECKS PASSED when shouldExitWithError is true', async () => {
|
|
160
|
+
const tempWorkspace = path.join(os.tmpdir(), 'pd-exit-test-' + Date.now());
|
|
161
|
+
mockExecFileSync.mockClear();
|
|
162
|
+
// Make all iterations fail (execFileSync throws) so shouldExitWithError returns true
|
|
163
|
+
mockExecFileSync.mockRejectedValue(new Error('simulated failure'));
|
|
164
|
+
capturedStderr.length = 0;
|
|
165
|
+
capturedExitCode = null;
|
|
166
|
+
|
|
167
|
+
await handleRuntimeUat({
|
|
168
|
+
workspace: tempWorkspace,
|
|
169
|
+
count: 1,
|
|
170
|
+
minSuccessRate: 1.0,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(capturedExitCode).toBe(1);
|
|
174
|
+
const stderrText = capturedStderr.join('\n');
|
|
175
|
+
expect(stderrText).not.toContain('ALL CHECKS PASSED');
|
|
176
|
+
});
|
|
177
|
+
});
|