@lumenflow/core 2.18.3 → 2.20.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/adapters/terminal-renderer.adapter.d.ts.map +1 -1
- package/dist/adapters/terminal-renderer.adapter.js +6 -4
- package/dist/adapters/terminal-renderer.adapter.js.map +1 -1
- package/dist/arg-parser.js +2 -2
- package/dist/arg-parser.js.map +1 -1
- package/dist/atomic-merge.d.ts +21 -0
- package/dist/atomic-merge.d.ts.map +1 -0
- package/dist/atomic-merge.js +83 -0
- package/dist/atomic-merge.js.map +1 -0
- package/dist/context/wu-state-reader.d.ts +2 -0
- package/dist/context/wu-state-reader.d.ts.map +1 -1
- package/dist/context/wu-state-reader.js +3 -0
- package/dist/context/wu-state-reader.js.map +1 -1
- package/dist/delegation-escalation.d.ts +91 -0
- package/dist/delegation-escalation.d.ts.map +1 -0
- package/dist/delegation-escalation.js +258 -0
- package/dist/delegation-escalation.js.map +1 -0
- package/dist/delegation-monitor.d.ts +230 -0
- package/dist/delegation-monitor.d.ts.map +1 -0
- package/dist/delegation-monitor.js +675 -0
- package/dist/delegation-monitor.js.map +1 -0
- package/dist/delegation-recovery.d.ts +83 -0
- package/dist/delegation-recovery.d.ts.map +1 -0
- package/dist/delegation-recovery.js +299 -0
- package/dist/delegation-recovery.js.map +1 -0
- package/dist/delegation-registry-schema.d.ts +80 -0
- package/dist/delegation-registry-schema.d.ts.map +1 -0
- package/dist/delegation-registry-schema.js +91 -0
- package/dist/delegation-registry-schema.js.map +1 -0
- package/dist/delegation-registry-store.d.ts +159 -0
- package/dist/delegation-registry-store.d.ts.map +1 -0
- package/dist/delegation-registry-store.js +299 -0
- package/dist/delegation-registry-store.js.map +1 -0
- package/dist/delegation-tree.d.ts +57 -0
- package/dist/delegation-tree.d.ts.map +1 -0
- package/dist/delegation-tree.js +203 -0
- package/dist/delegation-tree.js.map +1 -0
- package/dist/gates-agent-mode.d.ts +25 -0
- package/dist/gates-agent-mode.d.ts.map +1 -1
- package/dist/gates-agent-mode.js +41 -0
- package/dist/gates-agent-mode.js.map +1 -1
- package/dist/index.d.ts +16 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -9
- package/dist/index.js.map +1 -1
- package/dist/lumenflow-config-schema.d.ts +9 -3
- package/dist/lumenflow-config-schema.d.ts.map +1 -1
- package/dist/lumenflow-config-schema.js +19 -4
- package/dist/lumenflow-config-schema.js.map +1 -1
- package/dist/lumenflow-config.d.ts +2 -0
- package/dist/lumenflow-config.d.ts.map +1 -1
- package/dist/lumenflow-config.js +1 -0
- package/dist/lumenflow-config.js.map +1 -1
- package/dist/micro-worktree.d.ts.map +1 -1
- package/dist/micro-worktree.js +15 -9
- package/dist/micro-worktree.js.map +1 -1
- package/dist/rollback-utils.d.ts +52 -0
- package/dist/rollback-utils.d.ts.map +1 -1
- package/dist/rollback-utils.js +111 -0
- package/dist/rollback-utils.js.map +1 -1
- package/dist/sandbox-allowlist.d.ts +16 -0
- package/dist/sandbox-allowlist.d.ts.map +1 -0
- package/dist/sandbox-allowlist.js +75 -0
- package/dist/sandbox-allowlist.js.map +1 -0
- package/dist/sandbox-backend-linux.d.ts +6 -0
- package/dist/sandbox-backend-linux.d.ts.map +1 -0
- package/dist/sandbox-backend-linux.js +65 -0
- package/dist/sandbox-backend-linux.js.map +1 -0
- package/dist/sandbox-backend-macos.d.ts +6 -0
- package/dist/sandbox-backend-macos.d.ts.map +1 -0
- package/dist/sandbox-backend-macos.js +64 -0
- package/dist/sandbox-backend-macos.js.map +1 -0
- package/dist/sandbox-backend-windows.d.ts +6 -0
- package/dist/sandbox-backend-windows.d.ts.map +1 -0
- package/dist/sandbox-backend-windows.js +28 -0
- package/dist/sandbox-backend-windows.js.map +1 -0
- package/dist/sandbox-profile.d.ts +53 -0
- package/dist/sandbox-profile.d.ts.map +1 -0
- package/dist/sandbox-profile.js +62 -0
- package/dist/sandbox-profile.js.map +1 -0
- package/dist/schemas/index.d.ts +3 -3
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +6 -6
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/initiative-arg-validators.d.ts +1 -0
- package/dist/schemas/initiative-arg-validators.d.ts.map +1 -1
- package/dist/schemas/initiative-schemas.d.ts +3 -1
- package/dist/schemas/initiative-schemas.d.ts.map +1 -1
- package/dist/schemas/initiative-schemas.js +2 -1
- package/dist/schemas/initiative-schemas.js.map +1 -1
- package/dist/schemas/setup-arg-validators.d.ts +4 -4
- package/dist/schemas/setup-arg-validators.d.ts.map +1 -1
- package/dist/schemas/setup-arg-validators.js +6 -6
- package/dist/schemas/setup-arg-validators.js.map +1 -1
- package/dist/schemas/setup-schemas.d.ts +7 -7
- package/dist/schemas/setup-schemas.d.ts.map +1 -1
- package/dist/schemas/setup-schemas.js +11 -11
- package/dist/schemas/setup-schemas.js.map +1 -1
- package/dist/schemas/wu-lifecycle-arg-validators.d.ts +2 -1
- package/dist/schemas/wu-lifecycle-arg-validators.d.ts.map +1 -1
- package/dist/schemas/wu-lifecycle-schemas.d.ts +5 -3
- package/dist/schemas/wu-lifecycle-schemas.d.ts.map +1 -1
- package/dist/schemas/wu-lifecycle-schemas.js +6 -2
- package/dist/schemas/wu-lifecycle-schemas.js.map +1 -1
- package/dist/spawn-strategy.d.ts +1 -1
- package/dist/spawn-strategy.js +1 -1
- package/dist/template-loader.d.ts +7 -3
- package/dist/template-loader.d.ts.map +1 -1
- package/dist/template-loader.js +22 -6
- package/dist/template-loader.js.map +1 -1
- package/dist/validation/types.d.ts +2 -0
- package/dist/validation/types.d.ts.map +1 -1
- package/dist/wu-consistency-checker.d.ts +1 -0
- package/dist/wu-consistency-checker.d.ts.map +1 -1
- package/dist/wu-consistency-checker.js +31 -2
- package/dist/wu-consistency-checker.js.map +1 -1
- package/dist/wu-context-constants.d.ts +4 -2
- package/dist/wu-context-constants.d.ts.map +1 -1
- package/dist/wu-context-constants.js +4 -2
- package/dist/wu-context-constants.js.map +1 -1
- package/dist/wu-done-branch-only.d.ts +2 -11
- package/dist/wu-done-branch-only.d.ts.map +1 -1
- package/dist/wu-done-branch-only.js +81 -45
- package/dist/wu-done-branch-only.js.map +1 -1
- package/dist/wu-done-cleanup.js +33 -1
- package/dist/wu-done-cleanup.js.map +1 -1
- package/dist/wu-done-initiative-sync.d.ts.map +1 -1
- package/dist/wu-done-initiative-sync.js +20 -5
- package/dist/wu-done-initiative-sync.js.map +1 -1
- package/dist/wu-done-machine.d.ts +175 -0
- package/dist/wu-done-machine.d.ts.map +1 -0
- package/dist/wu-done-machine.js +225 -0
- package/dist/wu-done-machine.js.map +1 -0
- package/dist/wu-done-metadata.d.ts.map +1 -1
- package/dist/wu-done-metadata.js +3 -1
- package/dist/wu-done-metadata.js.map +1 -1
- package/dist/wu-done-preflight.d.ts +8 -0
- package/dist/wu-done-preflight.d.ts.map +1 -1
- package/dist/wu-done-preflight.js +17 -1
- package/dist/wu-done-preflight.js.map +1 -1
- package/dist/wu-done-validation.d.ts +0 -37
- package/dist/wu-done-validation.d.ts.map +1 -1
- package/dist/wu-done-validation.js +1 -155
- package/dist/wu-done-validation.js.map +1 -1
- package/dist/wu-done-validators.d.ts +1 -2
- package/dist/wu-done-validators.d.ts.map +1 -1
- package/dist/wu-done-validators.js +1 -3
- package/dist/wu-done-validators.js.map +1 -1
- package/dist/wu-done-worktree-services.d.ts +191 -0
- package/dist/wu-done-worktree-services.d.ts.map +1 -0
- package/dist/wu-done-worktree-services.js +273 -0
- package/dist/wu-done-worktree-services.js.map +1 -0
- package/dist/wu-done-worktree.d.ts +0 -19
- package/dist/wu-done-worktree.d.ts.map +1 -1
- package/dist/wu-done-worktree.js +165 -118
- package/dist/wu-done-worktree.js.map +1 -1
- package/dist/wu-git-constants.d.ts +4 -0
- package/dist/wu-git-constants.d.ts.map +1 -1
- package/dist/wu-git-constants.js +4 -0
- package/dist/wu-git-constants.js.map +1 -1
- package/dist/wu-helpers.d.ts +5 -1
- package/dist/wu-helpers.d.ts.map +1 -1
- package/dist/wu-helpers.js +5 -1
- package/dist/wu-helpers.js.map +1 -1
- package/dist/wu-lint.d.ts +53 -37
- package/dist/wu-lint.d.ts.map +1 -1
- package/dist/wu-lint.js +95 -105
- package/dist/wu-lint.js.map +1 -1
- package/dist/wu-paths-constants.d.ts +3 -3
- package/dist/wu-paths-constants.d.ts.map +1 -1
- package/dist/wu-paths-constants.js +3 -3
- package/dist/wu-paths-constants.js.map +1 -1
- package/dist/wu-preflight-validators.d.ts +28 -77
- package/dist/wu-preflight-validators.d.ts.map +1 -1
- package/dist/wu-preflight-validators.js +86 -130
- package/dist/wu-preflight-validators.js.map +1 -1
- package/dist/wu-recovery.d.ts +89 -0
- package/dist/wu-recovery.d.ts.map +1 -1
- package/dist/wu-recovery.js +118 -0
- package/dist/wu-recovery.js.map +1 -1
- package/dist/wu-rules-core.d.ts +95 -0
- package/dist/wu-rules-core.d.ts.map +1 -0
- package/dist/wu-rules-core.js +399 -0
- package/dist/wu-rules-core.js.map +1 -0
- package/dist/wu-rules-engine.d.ts +29 -0
- package/dist/wu-rules-engine.d.ts.map +1 -0
- package/dist/wu-rules-engine.js +59 -0
- package/dist/wu-rules-engine.js.map +1 -0
- package/dist/wu-rules-resolvers.d.ts +19 -0
- package/dist/wu-rules-resolvers.d.ts.map +1 -0
- package/dist/wu-rules-resolvers.js +208 -0
- package/dist/wu-rules-resolvers.js.map +1 -0
- package/dist/wu-schema.d.ts +24 -9
- package/dist/wu-schema.d.ts.map +1 -1
- package/dist/wu-schema.js +14 -1
- package/dist/wu-schema.js.map +1 -1
- package/dist/wu-spawn-context.d.ts +1 -1
- package/dist/wu-spawn-context.d.ts.map +1 -1
- package/dist/wu-spawn-context.js +8 -2
- package/dist/wu-spawn-context.js.map +1 -1
- package/dist/wu-spawn-helpers.js +2 -2
- package/dist/wu-spawn-helpers.js.map +1 -1
- package/dist/wu-state-schema.d.ts +12 -12
- package/dist/wu-state-schema.d.ts.map +1 -1
- package/dist/wu-state-schema.js +10 -10
- package/dist/wu-state-schema.js.map +1 -1
- package/dist/wu-state-store.d.ts +10 -4
- package/dist/wu-state-store.d.ts.map +1 -1
- package/dist/wu-state-store.js +309 -11
- package/dist/wu-state-store.js.map +1 -1
- package/dist/wu-transaction.d.ts +21 -0
- package/dist/wu-transaction.d.ts.map +1 -1
- package/dist/wu-transaction.js +17 -0
- package/dist/wu-transaction.js.map +1 -1
- package/package.json +14 -11
|
@@ -1,83 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Preflight validation functions for wu:preflight
|
|
3
|
+
* Preflight validation functions for wu:preflight and wu:done.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* This catches YAML mismatches early, saving time compared to full wu:done validation.
|
|
9
|
-
*
|
|
10
|
-
* Key validations:
|
|
11
|
-
* - WU YAML schema is valid (full canonical schema, not just required fields)
|
|
12
|
-
* - created field is YYYY-MM-DD format (fails fast on ISO timestamps)
|
|
13
|
-
* - code_paths files exist
|
|
14
|
-
* - test file paths exist (unit, e2e, integration - not manual)
|
|
15
|
-
*
|
|
16
|
-
* Design goals:
|
|
17
|
-
* - Complete in under 5 seconds
|
|
18
|
-
* - Clear error messages pointing to missing files
|
|
19
|
-
* - Reusable by wu:done for early validation
|
|
5
|
+
* Uses phase-aware rules from wu-rules-engine:
|
|
6
|
+
* - intent/structural: syntax + policy intent checks
|
|
7
|
+
* - reality: disk/diff/parity/test existence checks
|
|
20
8
|
*/
|
|
21
|
-
import { existsSync } from 'node:fs';
|
|
22
|
-
import path from 'node:path';
|
|
23
9
|
import { WU_PATHS } from './wu-paths.js';
|
|
24
10
|
import { readWURaw } from './wu-yaml.js';
|
|
25
11
|
import { TEST_TYPES, LOG_PREFIX, EMOJI } from './wu-constants.js';
|
|
26
|
-
// WU-1810: Import canonical schema for full validation
|
|
27
12
|
import { BaseWUSchema } from './wu-schema.js';
|
|
28
|
-
// WU-1810: Import fixer to detect fixable issues
|
|
29
13
|
import { detectFixableIssues, FIXABLE_ISSUES } from './wu-yaml-fixer.js';
|
|
30
14
|
import fg from 'fast-glob';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @typedef {object} PreflightResult
|
|
34
|
-
* @property {boolean} valid - Whether all validations passed
|
|
35
|
-
* @property {string[]} errors - List of error messages
|
|
36
|
-
* @property {string[]} missingCodePaths - Code paths that don't exist
|
|
37
|
-
* @property {string[]} missingTestPaths - Test file paths that don't exist
|
|
38
|
-
*/
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { isPathLikeTestEntry, pathReferenceExistsSync, validationIssueToDisplayLines, validateWURules, validateWURulesSync, } from './wu-rules-engine.js';
|
|
39
17
|
/**
|
|
40
18
|
* Create a PreflightResult object
|
|
41
|
-
*
|
|
42
|
-
* @param {object} params - Result parameters
|
|
43
|
-
* @param {boolean} params.valid - Whether validation passed
|
|
44
|
-
* @param {string[]} [params.errors=[]] - Error messages
|
|
45
|
-
* @param {string[]} [params.missingCodePaths=[]] - Missing code paths
|
|
46
|
-
* @param {string[]} [params.missingTestPaths=[]] - Missing test paths
|
|
47
|
-
* @param {Record<string, string[]>} [params.suggestedTestPaths={}] - Suggested test paths
|
|
48
|
-
* @returns {PreflightResult}
|
|
49
19
|
*/
|
|
50
|
-
export function createPreflightResult({ valid, errors = [], missingCodePaths = [], missingTestPaths = [], suggestedTestPaths = {}, }) {
|
|
20
|
+
export function createPreflightResult({ valid, errors = [], warnings = [], missingCodePaths = [], missingCoverageCodePaths = [], missingTestPaths = [], changedFiles = [], suggestedTestPaths = {}, }) {
|
|
51
21
|
return {
|
|
52
22
|
valid,
|
|
53
23
|
errors,
|
|
24
|
+
warnings,
|
|
54
25
|
missingCodePaths,
|
|
26
|
+
missingCoverageCodePaths,
|
|
55
27
|
missingTestPaths,
|
|
28
|
+
changedFiles,
|
|
56
29
|
suggestedTestPaths,
|
|
57
30
|
};
|
|
58
31
|
}
|
|
59
|
-
/**
|
|
60
|
-
* WU-1810: Validate WU YAML schema using canonical Zod schema
|
|
61
|
-
*
|
|
62
|
-
* Uses BaseWUSchema (structural validation) rather than minimal required fields.
|
|
63
|
-
* This catches created format issues, invalid type/status enums, etc. early.
|
|
64
|
-
*
|
|
65
|
-
* Special handling for created field:
|
|
66
|
-
* - Detects ISO timestamps and Date scalars via wu-yaml-fixer
|
|
67
|
-
* - Provides actionable error message suggesting auto-fix
|
|
68
|
-
*
|
|
69
|
-
* @param {object} doc - Parsed WU YAML document
|
|
70
|
-
* @param {string} id - Expected WU ID
|
|
71
|
-
* @returns {{ valid: boolean, errors: string[] }}
|
|
72
|
-
*/
|
|
73
32
|
function validateSchema(doc, id) {
|
|
74
33
|
const errors = [];
|
|
75
|
-
// Check ID matches (before schema validation for clear error)
|
|
76
34
|
if (doc.id !== id) {
|
|
77
35
|
errors.push(`WU ID mismatch: expected ${id}, found ${doc.id}`);
|
|
78
36
|
}
|
|
79
|
-
// WU-1810: Check for fixable issues (especially created field)
|
|
80
|
-
// This provides better error messages than raw Zod schema errors
|
|
81
37
|
const fixableIssues = detectFixableIssues(doc);
|
|
82
38
|
const createdIssue = fixableIssues.find((issue) => issue.type === FIXABLE_ISSUES.DATE_ISO_TIMESTAMP);
|
|
83
39
|
if (createdIssue) {
|
|
@@ -85,14 +41,11 @@ function validateSchema(doc, id) {
|
|
|
85
41
|
`Expected YYYY-MM-DD format. Suggested fix: change to "${createdIssue.suggested}". ` +
|
|
86
42
|
`Fix by editing the WU YAML file (created: '${createdIssue.suggested}').`);
|
|
87
43
|
}
|
|
88
|
-
// WU-1810: Validate against canonical Zod schema
|
|
89
44
|
const schemaResult = BaseWUSchema.safeParse(doc);
|
|
90
45
|
if (!schemaResult.success) {
|
|
91
|
-
// Format Zod errors with field paths
|
|
92
46
|
for (const issue of schemaResult.error.issues) {
|
|
93
47
|
const fieldPath = issue.path.join('.');
|
|
94
48
|
const message = issue.message;
|
|
95
|
-
// Skip created errors if we already reported a fixable issue
|
|
96
49
|
if (fieldPath === 'created' && createdIssue) {
|
|
97
50
|
continue;
|
|
98
51
|
}
|
|
@@ -102,13 +55,7 @@ function validateSchema(doc, id) {
|
|
|
102
55
|
return { valid: errors.length === 0, errors };
|
|
103
56
|
}
|
|
104
57
|
/**
|
|
105
|
-
* Validate code_paths files exist
|
|
106
|
-
*
|
|
107
|
-
* WU-1329: Exported for use by wu:create strict validation.
|
|
108
|
-
*
|
|
109
|
-
* @param {string[]} codePaths - List of code paths from WU YAML
|
|
110
|
-
* @param {string} rootDir - Root directory to resolve paths against
|
|
111
|
-
* @returns {{ valid: boolean, errors: string[], missing: string[] }}
|
|
58
|
+
* Validate code_paths files/globs exist on disk.
|
|
112
59
|
*/
|
|
113
60
|
export function validateCodePathsExistence(codePaths, rootDir) {
|
|
114
61
|
if (!codePaths || !Array.isArray(codePaths) || codePaths.length === 0) {
|
|
@@ -118,14 +65,13 @@ export function validateCodePathsExistence(codePaths, rootDir) {
|
|
|
118
65
|
for (const filePath of codePaths) {
|
|
119
66
|
if (!filePath || typeof filePath !== 'string')
|
|
120
67
|
continue;
|
|
121
|
-
|
|
122
|
-
if (!existsSync(fullPath)) {
|
|
68
|
+
if (!pathReferenceExistsSync(filePath, rootDir)) {
|
|
123
69
|
missing.push(filePath);
|
|
124
70
|
}
|
|
125
71
|
}
|
|
126
72
|
if (missing.length > 0) {
|
|
127
73
|
const errors = [
|
|
128
|
-
`code_paths validation failed - ${missing.length}
|
|
74
|
+
`code_paths validation failed - ${missing.length} path(s) not found:`,
|
|
129
75
|
...missing.map((p) => ` - ${p}`),
|
|
130
76
|
];
|
|
131
77
|
return { valid: false, errors, missing };
|
|
@@ -133,22 +79,16 @@ export function validateCodePathsExistence(codePaths, rootDir) {
|
|
|
133
79
|
return { valid: true, errors: [], missing: [] };
|
|
134
80
|
}
|
|
135
81
|
/**
|
|
136
|
-
* Validate test file paths exist
|
|
137
|
-
*
|
|
138
|
-
* Manual tests are descriptions, not file paths, so they're skipped.
|
|
82
|
+
* Validate automated test file paths/globs exist.
|
|
139
83
|
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* @param {object} tests - tests object from WU YAML
|
|
143
|
-
* @param {string} rootDir - Root directory to resolve paths against
|
|
144
|
-
* @returns {{ valid: boolean, errors: string[], missing: string[] }}
|
|
84
|
+
* Non-path-like prose entries are ignored here; they are classified by
|
|
85
|
+
* reality-phase rule R-007.
|
|
145
86
|
*/
|
|
146
87
|
export function validateTestPathsExistence(tests, rootDir) {
|
|
147
88
|
if (!tests || typeof tests !== 'object') {
|
|
148
89
|
return { valid: true, errors: [], missing: [] };
|
|
149
90
|
}
|
|
150
91
|
const missing = [];
|
|
151
|
-
// Test types that are file paths (not manual descriptions)
|
|
152
92
|
const fileTestTypes = [TEST_TYPES.UNIT, TEST_TYPES.E2E, TEST_TYPES.INTEGRATION];
|
|
153
93
|
for (const testType of fileTestTypes) {
|
|
154
94
|
const paths = tests[testType];
|
|
@@ -157,15 +97,16 @@ export function validateTestPathsExistence(tests, rootDir) {
|
|
|
157
97
|
for (const filePath of paths) {
|
|
158
98
|
if (!filePath || typeof filePath !== 'string')
|
|
159
99
|
continue;
|
|
160
|
-
|
|
161
|
-
|
|
100
|
+
if (!isPathLikeTestEntry(filePath))
|
|
101
|
+
continue;
|
|
102
|
+
if (!pathReferenceExistsSync(filePath, rootDir)) {
|
|
162
103
|
missing.push(filePath);
|
|
163
104
|
}
|
|
164
105
|
}
|
|
165
106
|
}
|
|
166
107
|
if (missing.length > 0) {
|
|
167
108
|
const errors = [
|
|
168
|
-
`test paths validation failed - ${missing.length} test
|
|
109
|
+
`test paths validation failed - ${missing.length} automated test path(s) not found:`,
|
|
169
110
|
...missing.map((p) => ` - ${p}`),
|
|
170
111
|
];
|
|
171
112
|
return { valid: false, errors, missing };
|
|
@@ -175,20 +116,16 @@ export function validateTestPathsExistence(tests, rootDir) {
|
|
|
175
116
|
export async function validatePreflight(id, options = {}) {
|
|
176
117
|
const rootDir = options.rootDir || process.cwd();
|
|
177
118
|
const worktreePath = options.worktreePath || rootDir;
|
|
119
|
+
const phase = options.phase || 'reality';
|
|
178
120
|
const allErrors = [];
|
|
121
|
+
const allWarnings = [];
|
|
179
122
|
const missingCodePaths = [];
|
|
123
|
+
const missingCoverageCodePaths = [];
|
|
180
124
|
const missingTestPaths = [];
|
|
181
|
-
|
|
182
|
-
// When worktreePath is provided, read YAML from there to get latest code_paths
|
|
125
|
+
const changedFiles = [];
|
|
183
126
|
const wuPath = path.join(worktreePath, WU_PATHS.WU(id));
|
|
184
|
-
// Debug logging for YAML source (WU-1830)
|
|
185
|
-
if (options.worktreePath && options.worktreePath !== rootDir) {
|
|
186
|
-
if (process.env.DEBUG)
|
|
187
|
-
console.log(`[wu-preflight] Reading WU YAML from worktree: ${wuPath}`);
|
|
188
|
-
}
|
|
189
127
|
let doc;
|
|
190
128
|
try {
|
|
191
|
-
// First try to read raw (without ID validation) to provide better errors
|
|
192
129
|
doc = readWURaw(wuPath);
|
|
193
130
|
}
|
|
194
131
|
catch (err) {
|
|
@@ -197,26 +134,33 @@ export async function validatePreflight(id, options = {}) {
|
|
|
197
134
|
errors: [`Failed to read WU YAML: ${err.message}`],
|
|
198
135
|
});
|
|
199
136
|
}
|
|
200
|
-
// Step 2: Validate schema
|
|
201
137
|
const schemaResult = validateSchema(doc, id);
|
|
202
138
|
if (!schemaResult.valid) {
|
|
203
139
|
allErrors.push(...schemaResult.errors);
|
|
204
140
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
141
|
+
const rulesContext = {
|
|
142
|
+
id,
|
|
143
|
+
type: doc.type,
|
|
144
|
+
status: doc.status,
|
|
145
|
+
code_paths: doc.code_paths,
|
|
146
|
+
tests: doc.tests || doc.test_paths || {},
|
|
147
|
+
cwd: worktreePath,
|
|
148
|
+
baseRef: options.baseRef,
|
|
149
|
+
headRef: options.headRef,
|
|
150
|
+
};
|
|
151
|
+
const rulesResult = phase === 'reality'
|
|
152
|
+
? await validateWURules(rulesContext, { phase })
|
|
153
|
+
: validateWURulesSync(rulesContext, { phase });
|
|
154
|
+
for (const issue of rulesResult.errors) {
|
|
155
|
+
allErrors.push(...validationIssueToDisplayLines(issue));
|
|
210
156
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const testsObj = doc.tests || doc.test_paths || {};
|
|
214
|
-
const testPathsResult = validateTestPathsExistence(testsObj, worktreePath);
|
|
215
|
-
if (!testPathsResult.valid) {
|
|
216
|
-
allErrors.push(...testPathsResult.errors);
|
|
217
|
-
missingTestPaths.push(...testPathsResult.missing);
|
|
157
|
+
for (const issue of rulesResult.warnings) {
|
|
158
|
+
allWarnings.push(...validationIssueToDisplayLines(issue));
|
|
218
159
|
}
|
|
219
|
-
|
|
160
|
+
missingCodePaths.push(...rulesResult.metadata.missingCodePaths);
|
|
161
|
+
missingCoverageCodePaths.push(...rulesResult.metadata.missingCoverageCodePaths);
|
|
162
|
+
missingTestPaths.push(...rulesResult.metadata.missingTestPaths);
|
|
163
|
+
changedFiles.push(...rulesResult.metadata.changedFiles);
|
|
220
164
|
let suggestedTestPaths = {};
|
|
221
165
|
if (missingTestPaths.length > 0) {
|
|
222
166
|
const searchRoot = worktreePath || rootDir;
|
|
@@ -224,63 +168,80 @@ export async function validatePreflight(id, options = {}) {
|
|
|
224
168
|
suggestedTestPaths = await findSuggestedTestPaths(missingTestPaths, searchRoot);
|
|
225
169
|
}
|
|
226
170
|
catch (err) {
|
|
227
|
-
if (process.env.DEBUG)
|
|
171
|
+
if (process.env.DEBUG) {
|
|
228
172
|
console.log(`[wu-preflight] Failed to find suggestions: ${err.message}`);
|
|
173
|
+
}
|
|
229
174
|
}
|
|
230
175
|
}
|
|
231
176
|
return createPreflightResult({
|
|
232
177
|
valid: allErrors.length === 0,
|
|
233
178
|
errors: allErrors,
|
|
179
|
+
warnings: allWarnings,
|
|
234
180
|
missingCodePaths,
|
|
181
|
+
missingCoverageCodePaths,
|
|
235
182
|
missingTestPaths,
|
|
183
|
+
changedFiles,
|
|
236
184
|
suggestedTestPaths,
|
|
237
185
|
});
|
|
238
186
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Format preflight result as user-friendly message
|
|
241
|
-
*
|
|
242
|
-
* @param {string} id - WU ID
|
|
243
|
-
* @param {PreflightResult} result - Validation result
|
|
244
|
-
* @returns {string} Formatted message
|
|
245
|
-
*/
|
|
246
187
|
export function formatPreflightResult(id, result) {
|
|
247
188
|
if (result.valid) {
|
|
248
|
-
|
|
189
|
+
const lines = [
|
|
190
|
+
`${LOG_PREFIX.PREFLIGHT} ${EMOJI.SUCCESS} Preflight validation passed for ${id}`,
|
|
191
|
+
];
|
|
192
|
+
if (Array.isArray(result.warnings) && result.warnings.length > 0) {
|
|
193
|
+
lines.push('');
|
|
194
|
+
lines.push(`${LOG_PREFIX.PREFLIGHT} ${EMOJI.WARNING} Warnings:`);
|
|
195
|
+
lines.push(...result.warnings.map((warning) => ` - ${warning}`));
|
|
196
|
+
}
|
|
197
|
+
return lines.join('\n');
|
|
249
198
|
}
|
|
250
199
|
const lines = [
|
|
251
200
|
`${LOG_PREFIX.PREFLIGHT} ${EMOJI.FAILURE} Preflight validation failed for ${id}`,
|
|
252
201
|
'',
|
|
253
202
|
...result.errors,
|
|
254
203
|
];
|
|
204
|
+
if (Array.isArray(result.warnings) && result.warnings.length > 0) {
|
|
205
|
+
lines.push('');
|
|
206
|
+
lines.push(`${LOG_PREFIX.PREFLIGHT} ${EMOJI.WARNING} Warnings:`);
|
|
207
|
+
lines.push(...result.warnings.map((warning) => ` - ${warning}`));
|
|
208
|
+
}
|
|
255
209
|
if (result.missingCodePaths.length > 0) {
|
|
256
210
|
lines.push('');
|
|
257
|
-
lines.push('Fix options:');
|
|
258
|
-
lines.push(' 1. Create the missing files');
|
|
211
|
+
lines.push('Fix options for missing code_paths:');
|
|
212
|
+
lines.push(' 1. Create the missing files/glob targets');
|
|
259
213
|
lines.push(` 2. Update code_paths in ${id}.yaml to match actual files`);
|
|
260
214
|
}
|
|
215
|
+
if (result.missingCoverageCodePaths.length > 0) {
|
|
216
|
+
lines.push('');
|
|
217
|
+
lines.push('Fix options for code_paths coverage vs branch diff:');
|
|
218
|
+
lines.push(' 1. Commit changes that touch each missing scoped code_path');
|
|
219
|
+
lines.push(` 2. Update code_paths in ${id}.yaml to match actual branch scope`);
|
|
220
|
+
lines.push(` 3. Re-run: pnpm wu:prep --id ${id}`);
|
|
221
|
+
}
|
|
261
222
|
if (result.missingTestPaths.length > 0) {
|
|
262
223
|
lines.push('');
|
|
263
|
-
lines.push('
|
|
264
|
-
lines.push(' 1. Create the missing test files');
|
|
224
|
+
lines.push('Fix options for automated test paths:');
|
|
225
|
+
lines.push(' 1. Create the missing test files/glob targets');
|
|
265
226
|
lines.push(` 2. Update tests in ${id}.yaml to match actual files`);
|
|
266
|
-
lines.push(' 3.
|
|
227
|
+
lines.push(' 3. Move prose/non-path test notes into tests.manual');
|
|
267
228
|
}
|
|
268
229
|
return lines.join('\n');
|
|
269
230
|
}
|
|
270
|
-
// Export PreflightResult type for documentation
|
|
271
|
-
export const PreflightResult = {};
|
|
272
231
|
/**
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* @param {string[]} missingPaths - List of missing test paths
|
|
276
|
-
* @param {string} rootDir - Root directory to search in
|
|
277
|
-
* @returns {Promise<Record<string, string[]>>} Map of missing path -> suggestions
|
|
232
|
+
* Build display lines for preflight warnings with a consistent shape.
|
|
278
233
|
*/
|
|
234
|
+
export function formatPreflightWarnings(warnings, header = `${LOG_PREFIX.PREFLIGHT} ${EMOJI.WARNING} Warnings:`) {
|
|
235
|
+
if (!Array.isArray(warnings) || warnings.length === 0) {
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
return [header, ...warnings.map((warning) => ` - ${warning}`)];
|
|
239
|
+
}
|
|
240
|
+
export const PreflightResult = {};
|
|
279
241
|
export async function findSuggestedTestPaths(missingPaths, rootDir) {
|
|
280
242
|
const suggestions = {};
|
|
281
243
|
if (missingPaths.length === 0)
|
|
282
244
|
return suggestions;
|
|
283
|
-
// Cache strict searches to avoid re-reading fs
|
|
284
245
|
const globOptions = {
|
|
285
246
|
cwd: rootDir,
|
|
286
247
|
caseSensitiveMatch: false,
|
|
@@ -288,22 +249,17 @@ export async function findSuggestedTestPaths(missingPaths, rootDir) {
|
|
|
288
249
|
ignore: ['**/node_modules/**'],
|
|
289
250
|
};
|
|
290
251
|
for (const missingPath of missingPaths) {
|
|
291
|
-
const filename =
|
|
292
|
-
const basename =
|
|
252
|
+
const filename = missingPath.split('/').pop() || missingPath;
|
|
253
|
+
const basename = filename.replace(/\.[^/.]+$/, '');
|
|
293
254
|
const cleanBasename = basename.replace(/(\.test|\.spec)$/, '');
|
|
294
|
-
// Strategy 1: Search for exact filename elsewhere
|
|
295
255
|
let matches = await fg(`**/${filename}`, globOptions);
|
|
296
|
-
// Strategy 2: Search for filename with different extension (ts/js/mjs)
|
|
297
256
|
if (matches.length === 0) {
|
|
298
257
|
matches = await fg(`**/${basename}.{ts,js,mjs,tsx,jsx}`, globOptions);
|
|
299
258
|
}
|
|
300
|
-
// Strategy 3: Search for fuzzy match on basename (without .test/.spec)
|
|
301
259
|
if (matches.length === 0) {
|
|
302
|
-
// Look for the code file the test might be for
|
|
303
260
|
matches = await fg(`**/${cleanBasename}.{ts,js,mjs,tsx,jsx}`, globOptions);
|
|
304
261
|
}
|
|
305
262
|
if (matches.length > 0) {
|
|
306
|
-
// Filter out the missing path itself if it somehow showed up
|
|
307
263
|
suggestions[missingPath] = matches.filter((m) => m !== missingPath);
|
|
308
264
|
}
|
|
309
265
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wu-preflight-validators.js","sourceRoot":"","sources":["../src/wu-preflight-validators.ts"],"names":[],"mappings":";AAEA
|
|
1
|
+
{"version":3,"file":"wu-preflight-validators.js","sourceRoot":"","sources":["../src/wu-preflight-validators.ts"],"names":[],"mappings":";AAE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;YACvB,WAAW,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/dist/wu-recovery.d.ts
CHANGED
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
* NOTE (WU-1826): Core recovery functions are now re-exported from
|
|
14
14
|
* tools/lib/wu-repair-core.ts for use by the unified wu:repair command.
|
|
15
15
|
* This module remains the canonical implementation used by wu-done.ts.
|
|
16
|
+
*
|
|
17
|
+
* WU-1665: Adds state-machine-driven recovery consolidation.
|
|
18
|
+
* - StateMachineRecoveryManager determines rollback scope from pipeline failedAt state.
|
|
19
|
+
* - Legacy rollback path retained behind LUMENFLOW_LEGACY_ROLLBACK=1 env flag.
|
|
20
|
+
* - All recovery is now centralized through state-machine semantics by default.
|
|
16
21
|
*/
|
|
17
22
|
/**
|
|
18
23
|
* WU-1335: Maximum number of recovery attempts before escalating to manual intervention
|
|
@@ -136,4 +141,88 @@ export declare function recoverZombieState({ id, doc, _worktreePath, _args }: {
|
|
|
136
141
|
reason?: string;
|
|
137
142
|
};
|
|
138
143
|
}>;
|
|
144
|
+
/**
|
|
145
|
+
* WU-1665: Environment variable key for legacy rollback compatibility guard.
|
|
146
|
+
* When set to "1", the legacy rollback path is used instead of state-machine-driven recovery.
|
|
147
|
+
*/
|
|
148
|
+
export declare const LUMENFLOW_LEGACY_ROLLBACK_ENV_KEY = "LUMENFLOW_LEGACY_ROLLBACK";
|
|
149
|
+
/**
|
|
150
|
+
* WU-1665: Check if legacy rollback mode is enabled via environment variable.
|
|
151
|
+
*
|
|
152
|
+
* During the migration window, operators can set LUMENFLOW_LEGACY_ROLLBACK=1
|
|
153
|
+
* to use the pre-WU-1665 recovery path for rollback operations.
|
|
154
|
+
*
|
|
155
|
+
* @returns {boolean} True if legacy rollback is enabled
|
|
156
|
+
*/
|
|
157
|
+
export declare function isLegacyRollbackEnabled(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* WU-1665: Rollback scope determined by the pipeline state where failure occurred.
|
|
160
|
+
*
|
|
161
|
+
* Maps each pipeline stage to the recovery actions needed:
|
|
162
|
+
* - validating/preparing: nothing written, no rollback needed
|
|
163
|
+
* - gating: nothing written (gates are read-only checks), no rollback needed
|
|
164
|
+
* - committing: files written to disk, need snapshot restore
|
|
165
|
+
* - merging: committed to worktree branch, need snapshot + branch rollback
|
|
166
|
+
* - pushing: merged but push failed, need snapshot + branch rollback
|
|
167
|
+
* - cleaningUp: push succeeded, only worktree cleanup remains
|
|
168
|
+
*/
|
|
169
|
+
export interface RollbackScope {
|
|
170
|
+
/** Whether file snapshot restore is needed (files were written to disk) */
|
|
171
|
+
snapshotRestore: boolean;
|
|
172
|
+
/** Whether branch-level rollback is needed (commits were made) */
|
|
173
|
+
branchRollback: boolean;
|
|
174
|
+
/** Whether worktree cleanup is the remaining action (push already succeeded) */
|
|
175
|
+
worktreeCleanup: boolean;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* WU-1665: Recovery state from the XState pipeline snapshot.
|
|
179
|
+
*/
|
|
180
|
+
export interface PipelineRecoveryState {
|
|
181
|
+
wuId: string;
|
|
182
|
+
failedAt: string | null;
|
|
183
|
+
error: string | null;
|
|
184
|
+
retryCount: number;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* WU-1665: State-machine-driven recovery manager.
|
|
188
|
+
*
|
|
189
|
+
* Determines rollback scope from the pipeline's failedAt state, replacing
|
|
190
|
+
* the ad-hoc per-function rollback logic scattered across wu-recovery.ts,
|
|
191
|
+
* wu-transaction.ts, and rollback-utils.ts.
|
|
192
|
+
*
|
|
193
|
+
* Usage:
|
|
194
|
+
* ```ts
|
|
195
|
+
* const manager = new StateMachineRecoveryManager({
|
|
196
|
+
* wuId: 'WU-1665',
|
|
197
|
+
* failedAt: 'committing',
|
|
198
|
+
* error: 'git commit failed',
|
|
199
|
+
* retryCount: 0,
|
|
200
|
+
* });
|
|
201
|
+
* const scope = manager.getRollbackScope();
|
|
202
|
+
* // scope.snapshotRestore === true
|
|
203
|
+
* // scope.branchRollback === false
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
export declare class StateMachineRecoveryManager {
|
|
207
|
+
readonly wuId: string;
|
|
208
|
+
readonly failedAt: string | null;
|
|
209
|
+
readonly error: string | null;
|
|
210
|
+
readonly retryCount: number;
|
|
211
|
+
constructor(state: PipelineRecoveryState);
|
|
212
|
+
/**
|
|
213
|
+
* Determine rollback scope based on the pipeline stage where failure occurred.
|
|
214
|
+
*
|
|
215
|
+
* The scope is deterministic: given the same failedAt state, the same
|
|
216
|
+
* rollback actions are always prescribed.
|
|
217
|
+
*/
|
|
218
|
+
getRollbackScope(): RollbackScope;
|
|
219
|
+
/**
|
|
220
|
+
* Serialize recovery state for persistence (e.g., to .lumenflow/recovery/).
|
|
221
|
+
*/
|
|
222
|
+
serialize(): string;
|
|
223
|
+
/**
|
|
224
|
+
* Deserialize recovery state from persisted JSON.
|
|
225
|
+
*/
|
|
226
|
+
static deserialize(json: string): StateMachineRecoveryManager;
|
|
227
|
+
}
|
|
139
228
|
//# sourceMappingURL=wu-recovery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wu-recovery.d.ts","sourceRoot":"","sources":["../src/wu-recovery.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"wu-recovery.d.ts","sourceRoot":"","sources":["../src/wu-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAiBH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAqC,CAAC;AAOxE;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,KAAA,EAAE,OAAO,SAAgB,UAEhE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,KAAA,EAAE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