forked from santifer/career-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-all.mjs
More file actions
312 lines (261 loc) · 10.7 KB
/
test-all.mjs
File metadata and controls
312 lines (261 loc) · 10.7 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/bin/env node
/**
* test-all.mjs — Comprehensive test suite for career-ops
*
* Run before merging any PR or pushing changes.
* Tests: syntax, scripts, dashboard, data contract, personal data, paths.
*
* Usage:
* node test-all.mjs # Run all tests
* node test-all.mjs --quick # Skip dashboard build (faster)
*/
import { execSync, execFileSync } from 'child_process';
import { readFileSync, existsSync, readdirSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = __dirname;
const QUICK = process.argv.includes('--quick');
let passed = 0;
let failed = 0;
let warnings = 0;
function pass(msg) { console.log(` ✅ ${msg}`); passed++; }
function fail(msg) { console.log(` ❌ ${msg}`); failed++; }
function warn(msg) { console.log(` ⚠️ ${msg}`); warnings++; }
function run(cmd, args = [], opts = {}) {
try {
if (Array.isArray(args) && args.length > 0) {
return execFileSync(cmd, args, { cwd: ROOT, encoding: 'utf-8', timeout: 30000, ...opts }).trim();
}
return execSync(cmd, { cwd: ROOT, encoding: 'utf-8', timeout: 30000, ...opts }).trim();
} catch (e) {
return null;
}
}
function fileExists(path) { return existsSync(join(ROOT, path)); }
function readFile(path) { return readFileSync(join(ROOT, path), 'utf-8'); }
console.log('\n🧪 career-ops test suite\n');
// ── 1. SYNTAX CHECKS ────────────────────────────────────────────
console.log('1. Syntax checks');
const mjsFiles = readdirSync(ROOT).filter(f => f.endsWith('.mjs'));
for (const f of mjsFiles) {
const result = run('node', ['--check', f]);
if (result !== null) {
pass(`${f} syntax OK`);
} else {
fail(`${f} has syntax errors`);
}
}
// ── 2. SCRIPT EXECUTION ─────────────────────────────────────────
console.log('\n2. Script execution (graceful on empty data)');
const scripts = [
{ name: 'cv-sync-check.mjs', expectExit: 1, allowFail: true }, // fails without cv.md (normal in repo)
{ name: 'verify-pipeline.mjs', expectExit: 0 },
{ name: 'normalize-statuses.mjs', expectExit: 0 },
{ name: 'dedup-tracker.mjs', expectExit: 0 },
{ name: 'merge-tracker.mjs', expectExit: 0 },
{ name: 'update-system.mjs check', expectExit: 0 },
];
for (const { name, allowFail } of scripts) {
const result = run('node', name.split(' '), { stdio: ['pipe', 'pipe', 'pipe'] });
if (result !== null) {
pass(`${name} runs OK`);
} else if (allowFail) {
warn(`${name} exited with error (expected without user data)`);
} else {
fail(`${name} crashed`);
}
}
// ── 3. LIVENESS CLASSIFICATION ──────────────────────────────────
console.log('\n3. Liveness classification');
try {
const { classifyLiveness } = await import(pathToFileURL(join(ROOT, 'liveness-core.mjs')).href);
const expiredChromeApply = classifyLiveness({
finalUrl: 'https://example.com/jobs/closed-role',
bodyText: 'Company Careers\nApply\nThe job you are looking for is no longer open.',
applyControls: [],
});
if (expiredChromeApply.result === 'expired') {
pass('Expired pages are not revived by nav/footer "Apply" text');
} else {
fail(`Expired page misclassified as ${expiredChromeApply.result}`);
}
const activeWorkdayPage = classifyLiveness({
finalUrl: 'https://example.workday.com/job/123',
bodyText: [
'663 JOBS FOUND',
'Senior AI Engineer',
'Join our applied AI team to ship production systems, partner with customers, and own delivery across evaluation, deployment, and reliability.',
].join('\n'),
applyControls: ['Apply for this Job'],
});
if (activeWorkdayPage.result === 'active') {
pass('Visible apply controls still keep real job pages active');
} else {
fail(`Active job page misclassified as ${activeWorkdayPage.result}`);
}
} catch (e) {
fail(`Liveness classification tests crashed: ${e.message}`);
}
// ── 4. DASHBOARD BUILD ──────────────────────────────────────────
if (!QUICK) {
console.log('\n4. Dashboard build');
const goBuild = run('cd dashboard && go build -o /tmp/career-dashboard-test . 2>&1');
if (goBuild !== null) {
pass('Dashboard compiles');
} else {
fail('Dashboard build failed');
}
} else {
console.log('\n4. Dashboard build (skipped --quick)');
}
// ── 5. DATA CONTRACT ────────────────────────────────────────────
console.log('\n5. Data contract validation');
// Check system files exist
const systemFiles = [
'CLAUDE.md', 'VERSION', 'DATA_CONTRACT.md',
'modes/_shared.md', 'modes/_profile.template.md',
'modes/oferta.md', 'modes/pdf.md', 'modes/scan.md',
'templates/states.yml', 'templates/cv-template.html',
'.claude/skills/career-ops/SKILL.md',
];
for (const f of systemFiles) {
if (fileExists(f)) {
pass(`System file exists: ${f}`);
} else {
fail(`Missing system file: ${f}`);
}
}
// Check user files are NOT tracked (gitignored)
const userFiles = [
'config/profile.yml', 'modes/_profile.md', 'portals.yml',
];
for (const f of userFiles) {
const tracked = run('git', ['ls-files', f]);
if (tracked === '') {
pass(`User file gitignored: ${f}`);
} else if (tracked === null) {
pass(`User file gitignored: ${f}`);
} else {
fail(`User file IS tracked (should be gitignored): ${f}`);
}
}
// ── 6. PERSONAL DATA LEAK CHECK ─────────────────────────────────
console.log('\n6. Personal data leak check');
const leakPatterns = [
'Santiago', 'santifer.io', 'Santifer iRepair', 'Zinkee', 'ALMAS',
'hi@santifer.io', '688921377', '/Users/santifer/',
];
const scanExtensions = ['md', 'yml', 'html', 'mjs', 'sh', 'go', 'json'];
const allowedFiles = [
// English README + localized translations (all legitimately credit Santiago)
'README.md', 'README.es.md', 'README.ja.md', 'README.ko-KR.md',
'README.pt-BR.md', 'README.ru.md',
// Standard project files
'LICENSE', 'CITATION.cff', 'CONTRIBUTING.md',
'package.json', '.github/FUNDING.yml', 'CLAUDE.md', 'go.mod', 'test-all.mjs',
// Community / governance files (added in v1.3.0, all legitimately reference the maintainer)
'CODE_OF_CONDUCT.md', 'GOVERNANCE.md', 'SECURITY.md', 'SUPPORT.md',
'.github/SECURITY.md',
// Dashboard credit string
'dashboard/internal/ui/screens/pipeline.go',
];
// Build pathspec for git grep — only scan tracked files matching these
// extensions. This is what `grep -rn` was trying to do, but git-aware:
// untracked files (debate artifacts, AI tool scratch, local plans/) and
// gitignored files can't trigger false positives because they were never
// going to reach a commit anyway.
const grepPathspec = scanExtensions.map(e => `'*.${e}'`).join(' ');
let leakFound = false;
for (const pattern of leakPatterns) {
const result = run(
`git grep -n "${pattern}" -- ${grepPathspec} 2>/dev/null`
);
if (result) {
for (const line of result.split('\n')) {
const file = line.split(':')[0];
if (allowedFiles.some(a => file.includes(a))) continue;
if (file.includes('dashboard/go.mod')) continue;
warn(`Possible personal data in ${file}: "${pattern}"`);
leakFound = true;
}
}
}
if (!leakFound) {
pass('No personal data leaks outside allowed files');
}
// ── 7. ABSOLUTE PATH CHECK ──────────────────────────────────────
console.log('\n7. Absolute path check');
// Same git grep approach: only scans tracked files. Untracked AI tool
// outputs, local debate artifacts, etc. can't false-positive here.
const absPathResult = run(
`git grep -n "/Users/" -- '*.mjs' '*.sh' '*.md' '*.go' '*.yml' 2>/dev/null | grep -v README.md | grep -v LICENSE | grep -v CLAUDE.md | grep -v test-all.mjs`
);
if (!absPathResult) {
pass('No absolute paths in code files');
} else {
for (const line of absPathResult.split('\n').filter(Boolean)) {
fail(`Absolute path: ${line.slice(0, 100)}`);
}
}
// ── 8. MODE FILE INTEGRITY ──────────────────────────────────────
console.log('\n8. Mode file integrity');
const expectedModes = [
'_shared.md', '_profile.template.md', 'oferta.md', 'pdf.md', 'scan.md',
'batch.md', 'apply.md', 'auto-pipeline.md', 'contacto.md', 'deep.md',
'ofertas.md', 'pipeline.md', 'project.md', 'tracker.md', 'training.md',
];
for (const mode of expectedModes) {
if (fileExists(`modes/${mode}`)) {
pass(`Mode exists: ${mode}`);
} else {
fail(`Missing mode: ${mode}`);
}
}
// Check _shared.md references _profile.md
const shared = readFile('modes/_shared.md');
if (shared.includes('_profile.md')) {
pass('_shared.md references _profile.md');
} else {
fail('_shared.md does NOT reference _profile.md');
}
// ── 9. CLAUDE.md INTEGRITY ──────────────────────────────────────
console.log('\n9. CLAUDE.md integrity');
const claude = readFile('CLAUDE.md');
const requiredSections = [
'Data Contract', 'Update Check', 'Ethical Use',
'Offer Verification', 'Canonical States', 'TSV Format',
'First Run', 'Onboarding',
];
for (const section of requiredSections) {
if (claude.includes(section)) {
pass(`CLAUDE.md has section: ${section}`);
} else {
fail(`CLAUDE.md missing section: ${section}`);
}
}
// ── 10. VERSION FILE ─────────────────────────────────────────────
console.log('\n10. Version file');
if (fileExists('VERSION')) {
const version = readFile('VERSION').trim();
if (/^\d+\.\d+\.\d+$/.test(version)) {
pass(`VERSION is valid semver: ${version}`);
} else {
fail(`VERSION is not valid semver: "${version}"`);
}
} else {
fail('VERSION file missing');
}
// ── SUMMARY ─────────────────────────────────────────────────────
console.log('\n' + '='.repeat(50));
console.log(`📊 Results: ${passed} passed, ${failed} failed, ${warnings} warnings`);
if (failed > 0) {
console.log('🔴 TESTS FAILED — do NOT push/merge until fixed\n');
process.exit(1);
} else if (warnings > 0) {
console.log('🟡 Tests passed with warnings — review before pushing\n');
process.exit(0);
} else {
console.log('🟢 All tests passed — safe to push/merge\n');
process.exit(0);
}