forked from career-ops-hq/career-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdater-migration-tests.mjs
More file actions
162 lines (144 loc) · 4.37 KB
/
Copy pathupdater-migration-tests.mjs
File metadata and controls
162 lines (144 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env node
/**
* updater-migration-tests.mjs — source-level safety checks for update-system.
*
* Protects cross-version migrations where an older installed updater must fetch
* newly introduced system paths without touching user data.
*/
import { readFileSync } from 'fs';
let passed = 0;
let failed = 0;
function pass(message) {
console.log(`PASS ${message}`);
passed++;
}
function fail(message) {
console.error(`FAIL ${message}`);
failed++;
}
let source = '';
try {
source = readFileSync('update-system.mjs', 'utf-8');
pass('update-system.mjs is readable');
} catch (error) {
fail(`update-system.mjs is readable: ${error.message}`);
process.exit(1);
}
function extractArray(name) {
const match = source.match(new RegExp(`const\\s+${name}\\s*=\\s*\\[([\\s\\S]*?)\\];`));
if (!match) {
fail(`${name} array exists`);
return [];
}
pass(`${name} array exists`);
return Array.from(match[1].matchAll(/['"]([^'"]+)['"]/g), (entry) => entry[1]);
}
const systemPaths = extractArray('SYSTEM_PATHS');
const userPaths = extractArray('USER_PATHS');
const bootstrapPaths = extractArray('BOOTSTRAP_PATHS');
const requiredSystemPaths = [
'modes/followup.md',
'modes/interview.md',
'modes/interview-prep.md',
'modes/patterns.md',
'modes/update.md',
'modes/ar/',
'modes/tr/',
'modes/ua/',
'batch/README.md',
'examples/',
'config/profile.example.yml',
'.env.example',
'.claude-plugin/',
'.qwen/',
'tracker-columns-tests.mjs',
'updater-migration-tests.mjs',
'README.ar.md',
'README.ja.md',
'README.ua.md',
'CHANGELOG.md',
'CODE_OF_CONDUCT.md',
'GOVERNANCE.md',
'SECURITY.md',
'SUPPORT.md',
'TRADEMARK.md',
];
const requiredBootstrapPaths = [
'.agents/',
'.opencode/skills/',
'providers/',
'liveness-browser.mjs',
'role-matcher.mjs',
'updater-migration-tests.mjs',
'tracker-columns-tests.mjs',
];
for (const path of requiredSystemPaths) {
if (systemPaths.includes(path)) pass(`SYSTEM_PATHS covers ${path}`);
else fail(`SYSTEM_PATHS missing ${path}`);
}
for (const path of requiredBootstrapPaths) {
if (bootstrapPaths.includes(path)) pass(`BOOTSTRAP_PATHS covers ${path}`);
else fail(`BOOTSTRAP_PATHS missing ${path}`);
}
const twoPassManifestChecks = [
{
name: 'apply has a re-exec guard',
pattern: /CAREER_OPS_UPDATE_REEXEC/,
},
{
name: 'apply first updates update-system.mjs from FETCH_HEAD',
pattern: /git\('checkout',\s*'FETCH_HEAD',\s*'--',\s*'update-system\.mjs'\)/,
},
{
name: 'apply re-execs through the current Node binary',
pattern: /execFileSync\(process\.execPath,\s*\[\s*'update-system\.mjs',\s*'apply'\s*\]/,
},
{
name: 'apply carries the original backup branch across re-exec',
pattern: /CAREER_OPS_UPDATE_BACKUP_BRANCH/,
},
{
name: 'apply reads the target updater manifest from FETCH_HEAD',
pattern: /git\('show',\s*'FETCH_HEAD:update-system\.mjs'\)/,
},
{
name: 'apply extracts SYSTEM_PATHS from the target updater',
pattern: /extractArrayFromSource\([^,]+,\s*'SYSTEM_PATHS'\)/,
},
{
name: 'apply merges local and target system manifests',
pattern: /mergePathLists\(SYSTEM_PATHS,\s*remoteSystemPaths[\s\S]*?\)/,
},
{
name: 'apply checks out the merged manifest instead of only the local manifest',
pattern: /for\s*\(const path of updatePaths\)/,
},
];
for (const check of twoPassManifestChecks) {
if (check.pattern.test(source)) pass(check.name);
else fail(check.name);
}
for (const userPath of ['cv.md', 'config/profile.yml', 'modes/_profile.md', 'portals.yml', 'data/', 'reports/']) {
if (userPaths.includes(userPath)) pass(`USER_PATHS protects ${userPath}`);
else fail(`USER_PATHS missing ${userPath}`);
}
const allowedSystemUserOverlap = new Set(['writing-samples/README.md']);
let hasSystemUserCollision = false;
for (const systemPath of systemPaths) {
const overlapsUserPath = userPaths.some((userPath) => {
if (allowedSystemUserOverlap.has(systemPath)) return false;
return systemPath === userPath || systemPath.startsWith(userPath);
});
if (overlapsUserPath) {
hasSystemUserCollision = true;
fail(`SYSTEM_PATHS must not update user path ${systemPath}`);
}
}
if (!hasSystemUserCollision) {
pass('SYSTEM_PATHS does not collide with USER_PATHS');
}
if (failed > 0) {
console.error(`\n${passed} passed, ${failed} failed`);
process.exit(1);
}
console.log(`\n${passed} passed, ${failed} failed`);