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
254 lines (209 loc) · 8.43 KB
/
test-all.mjs
File metadata and controls
254 lines (209 loc) · 8.43 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
#!/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 } from 'child_process';
import { readFileSync, existsSync, readdirSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } 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, opts = {}) {
try {
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} 2>&1`);
if (result !== null) {
pass(`${name} runs OK`);
} else if (allowFail) {
warn(`${name} exited with error (expected without user data)`);
} else {
fail(`${name} crashed`);
}
}
// ── 3. DASHBOARD BUILD ──────────────────────────────────────────
if (!QUICK) {
console.log('\n3. 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('\n3. Dashboard build (skipped --quick)');
}
// ── 4. DATA CONTRACT ────────────────────────────────────────────
console.log('\n4. 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}`);
}
}
// ── 5. PERSONAL DATA LEAK CHECK ─────────────────────────────────
console.log('\n5. 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 excludeDirs = ['node_modules', '.git', 'dashboard/go.sum'];
const allowedFiles = ['README.md', 'LICENSE', 'CITATION.cff', 'CONTRIBUTING.md',
'package.json', '.github/FUNDING.yml', 'CLAUDE.md', 'go.mod', 'test-all.mjs'];
let leakFound = false;
for (const pattern of leakPatterns) {
const result = run(
`grep -rn "${pattern}" --include="*.{${scanExtensions.join(',')}}" . 2>/dev/null | grep -v node_modules | grep -v ".git/" | grep -v go.sum`
);
if (result) {
for (const line of result.split('\n')) {
const file = line.split(':')[0].replace('./', '');
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');
}
// ── 6. ABSOLUTE PATH CHECK ──────────────────────────────────────
console.log('\n6. Absolute path check');
const absPathResult = run(
`grep -rn "/Users/" --include="*.mjs" --include="*.sh" --include="*.md" --include="*.go" --include="*.yml" . 2>/dev/null | grep -v node_modules | grep -v ".git/" | grep -v README.md | grep -v LICENSE | grep -v go.sum | 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)}`);
}
}
// ── 7. MODE FILE INTEGRITY ──────────────────────────────────────
console.log('\n7. 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');
}
// ── 8. CLAUDE.md INTEGRITY ──────────────────────────────────────
console.log('\n8. 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}`);
}
}
// ── 9. VERSION FILE ─────────────────────────────────────────────
console.log('\n9. 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);
}