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
1103 lines (950 loc) · 46.1 KB
/
Copy pathtest-all.mjs
File metadata and controls
1103 lines (950 loc) · 46.1 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/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, mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'fs';
import { join, dirname } from 'path';
import { tmpdir } from 'os';
import { fileURLToPath, pathToFileURL } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = __dirname;
const QUICK = process.argv.includes('--quick');
const NODE = process.execPath;
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: 'analyze-patterns.mjs --self-test', 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}`);
}
const closedMycareersfuture = classifyLiveness({
finalUrl: 'https://www.mycareersfuture.gov.sg/job/engineering/senior-staff-embedded-software-engineer',
bodyText: [
'Senior Staff Embedded Software Engineer',
'MaxLinear Asia Singapore Private Limited',
'9 applications Posted 27 Oct 2025 Closed on 26 Nov 2025',
'Applications have closed for this job',
'Log in to Apply',
"You'll need to log in with Singpass to verify your identity.",
'Roles & Responsibilities: design, develop and maintain embedded firmware for broadband communications ICs.',
].join('\n'),
applyControls: ['Log in to Apply'],
});
if (closedMycareersfuture.result === 'expired') {
pass('Closed postings with "Applications have closed" banner are detected');
} else {
fail(`Closed mycareersfuture posting misclassified as ${closedMycareersfuture.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', 'README.cn.md', 'README.zh-TW.md',
// Standard project files
'LICENSE', 'CITATION.cff', 'CONTRIBUTING.md', 'CHANGELOG.md', 'TRADEMARK.md',
'package.json', '.github/FUNDING.yml', 'CLAUDE.md', 'AGENTS.md', 'go.mod', 'test-all.mjs',
'.claude-plugin/marketplace.json', '.claude-plugin/plugin.json',
// 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',
'dashboard/internal/ui/screens/progress.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. LOCAL PARSER CONTRACT ────────────────────────────────────
console.log('\n9. Local parser contract');
const scanScript = readFile('scan.mjs');
if (
scanScript.includes('typeof company.name !== \'string\'') &&
scanScript.includes('company.name.trim()') &&
scanScript.includes('company.name.toLowerCase()')
) {
pass('scan.mjs guards company names before filtering');
} else {
fail('scan.mjs does not guard company names before filtering');
}
if (
scanScript.includes("skipIds: ['local-parser']") &&
scanScript.includes('local parser failed, used API fallback') &&
scanScript.includes('resolveProvider(company, providers')
) {
pass('scan.mjs falls back to ATS API when local parser fails');
} else {
fail('scan.mjs does not fall back to ATS API when local parser fails');
}
if (fileExists('providers/local-parser.mjs')) {
pass('local-parser provider module exists');
} else {
fail('local-parser provider module is missing');
}
const scanMode = fileExists('modes/scan.md') ? readFile('modes/scan.md') : '';
if (
scanMode.includes('local_parser_ok') &&
scanMode.includes('no repetir scraping caro') &&
scanMode.includes('nombre no listado en `local_parser_ok`')
) {
pass('scan.md skips expensive levels after successful local parser');
} else {
fail('scan.md missing local_parser_ok skip rules for agent scan');
}
if (!fileExists('scripts/parsers/cohere_jobs.py')) {
pass('Cohere parser example is not bundled as a runtime script');
} else {
fail('Cohere parser example is still bundled as a runtime script');
}
const portalExample = readFile('templates/portals.example.yml');
if (
!portalExample.includes('cohere_jobs.py') &&
portalExample.includes('scripts/parsers/example-js-company-jobs.js') &&
portalExample.includes('scripts/parsers/example_python_company_jobs.py') &&
portalExample.includes('already know their target careers URL')
) {
pass('portals example documents a generic local parser contract');
} else {
fail('portals example still points at a bundled Cohere parser');
}
// ── 10. AGENTS.md INTEGRITY ─────────────────────────────────────
console.log('\n10. AGENTS.md integrity');
const agents = readFile('AGENTS.md');
const requiredSections = [
'Data Contract', 'Update Check', 'Ethical Use',
'Offer Verification', 'Canonical States', 'TSV Format',
'First Run', 'Onboarding',
];
for (const section of requiredSections) {
if (agents.includes(section)) {
pass(`AGENTS.md has section: ${section}`);
} else {
fail(`AGENTS.md missing section: ${section}`);
}
}
// ── 11. VERSION FILE ─────────────────────────────────────────────
console.log('\n11. 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');
}
// ── 11. LOCATION FILTER — always_allow tier ───────────────────────
console.log('\n11. Location filter — always_allow tier');
try {
const { buildLocationFilter } = await import(pathToFileURL(join(ROOT, 'scan.mjs')).href);
const filter = buildLocationFilter({
always_allow: ['belgium', 'brussels'],
allow: ['europe', 'emea', 'remote'],
block: ['france', 'germany', 'united states'],
});
// Case 1: home-region passes regardless of other text
if (filter('Brussels, Belgium') === true) pass('Brussels, Belgium passes (always_allow hit)');
else fail('Brussels, Belgium should pass');
// Case 2: always_allow wins over block (THE motivating case for this tier)
if (filter('Remote, Belgium or France') === true) pass('Remote, Belgium or France passes (always_allow beats block)');
else fail('Remote, Belgium or France should pass — always_allow must win over block');
// Case 3: no always_allow hit, block still rejects
if (filter('Paris, France') === false) pass('Paris, France is rejected (block still applies)');
else fail('Paris, France should be rejected');
// Case 4: empty location → pass (existing semantics, unchanged)
if (filter('') === true) pass('empty location passes (unchanged semantics)');
else fail('empty location should pass');
// Case 5: case-insensitivity
if (filter('BRUSSELS, BELGIUM') === true) pass('case-insensitive match works');
else fail('case-insensitive match failed');
// Case 6: backward compatibility — no always_allow key behaves like stock allow/block
const stockFilter = buildLocationFilter({
allow: ['europe', 'remote'],
block: ['france'],
});
if (stockFilter('Remote, Belgium or France') === false) pass('without always_allow, block still wins (backward compatible)');
else fail('without always_allow, behaviour must match stock allow/block (block wins)');
// Case 7: null/missing locationFilter → pass-all filter (early-return path)
const nullFilter = buildLocationFilter(null);
if (nullFilter('Anywhere on Earth') === true && nullFilter('') === true) {
pass('null locationFilter returns a pass-all filter (early-return path)');
} else {
fail('null locationFilter should return a pass-all filter');
}
// Case 8: string-instead-of-array → wrapped to a 1-item list
const stringFilter = buildLocationFilter({ always_allow: 'belgium', block: ['france'] });
if (stringFilter('Remote, Belgium or France') === true) {
pass('always_allow as a bare string is wrapped to a single-item list');
} else {
fail('always_allow as a bare string should still work');
}
// Case 9: null/non-string items are filtered out (no crash, no false matches)
const messyFilter = buildLocationFilter({
always_allow: [null, 'belgium', 42, undefined],
block: ['france', null, 7],
});
if (messyFilter('Brussels, Belgium') === true && messyFilter('Paris, France') === false) {
pass('non-string entries (null, numbers, undefined) are filtered out without crashing');
} else {
fail('mixed-type keyword lists should not crash and should still match string entries');
}
// Case 10: all-null/non-string list → empty after normalization (no false rejects)
const allBadFilter = buildLocationFilter({ block: [null, 42, undefined], allow: ['remote'] });
if (allBadFilter('Remote') === true) {
pass('a block list with only non-string entries normalizes to [] (no false rejects)');
} else {
fail('non-string-only block list should not cause rejection');
}
// Case 11: empty / whitespace-only entries are dropped (would otherwise pass-all via includes(''))
const emptyKeywordFilter = buildLocationFilter({
always_allow: ['', ' '],
allow: ['remote'],
block: ['france'],
});
if (emptyKeywordFilter('Paris, France') === false) {
pass('empty/whitespace always_allow entries are dropped (no pass-all via includes(""))');
} else {
fail('empty always_allow entries should NOT bypass block — would have made the filter pass-all');
}
// Case 12: surrounding whitespace is trimmed so the keyword still matches
const whitespaceFilter = buildLocationFilter({
always_allow: [' Belgium ', '\tBrussels\n'],
block: ['france'],
});
if (whitespaceFilter('Remote, Belgium or France') === true) {
pass('whitespace-padded keywords still match after trim');
} else {
fail('" Belgium " should be trimmed and still match "Remote, Belgium or France"');
}
// Case 13: whitespace-only location is treated as missing (pass-all-tiers)
if (filter(' \t ') === true) pass('whitespace-only location passes (treated as missing)');
else fail('whitespace-only location should pass');
// Case 14: non-string location (number/object/null) → pass without throwing
let crashed = false;
try {
const r1 = filter(42);
const r2 = filter({ city: 'Brussels' });
const r3 = filter(null);
const r4 = filter(undefined);
if (r1 === true && r2 === true && r3 === true && r4 === true) {
pass('non-string location values (number, object, null, undefined) pass without throwing');
} else {
fail(`non-string location results: number=${r1}, object=${r2}, null=${r3}, undefined=${r4}`);
}
} catch (e) {
crashed = true;
fail(`non-string location crashed: ${e.message}`);
}
// Case 15: a malformed location (e.g. legacy object) does NOT bypass block when interpreted naively —
// the guard returns true (pass) BEFORE block/allow even run, which is correct: scoring/eval happens
// downstream from the scan filter, so malformed locations should fall through to the manual evaluation
// step rather than being silently dropped here.
if (filter(42) === true) pass('non-string locations are passed through to downstream evaluation, not silently dropped');
else fail('non-string locations should pass through');
} catch (e) {
fail(`always_allow tests crashed: ${e.message}`);
}
// ── 12. FOLLOW-UP CADENCE LOGIC ─────────────────────────────────
console.log('\n12. Follow-up cadence logic');
try {
const cadence = await import(pathToFileURL(join(ROOT, 'followup-cadence.mjs')).href);
// CLI regression: the import.meta.url guard must still let the module run as a CLI.
// Data-independent — default mode emits the result as JSON: a `metadata` object when
// the tracker has applications, or an `{error}` object (exit 1) when it is empty.
// Empty output would mean the guard wrongly suppressed main().
let cliOut = '';
try {
cliOut = execFileSync(NODE, [join(ROOT, 'followup-cadence.mjs')], { cwd: ROOT, encoding: 'utf-8', timeout: 30000 });
} catch (cliErr) {
cliOut = `${cliErr.stdout || ''}`; // exit 1 on an empty tracker is expected; keep stdout
}
let cliJson = null;
try { cliJson = JSON.parse(cliOut.trim()); } catch { /* leave null → fail below */ }
if (cliJson && typeof cliJson === 'object' && ('metadata' in cliJson || 'error' in cliJson)) {
pass('CLI still executes under the import.meta.url guard (emits result JSON)');
} else {
fail('CLI produced no structured JSON when run directly — import.meta.url guard may be broken');
}
// Date helpers
if (cadence.addDays(cadence.parseDate('2026-05-01'), 7) === '2026-05-08') {
pass('addDays advances a parsed date by N days (UTC)');
} else {
fail(`addDays produced ${cadence.addDays(cadence.parseDate('2026-05-01'), 7)}`);
}
if (cadence.daysBetween(cadence.parseDate('2026-05-01'), cadence.parseDate('2026-05-08')) === 7) {
pass('daysBetween counts whole days between two dates');
} else {
fail('daysBetween miscounted');
}
if (cadence.parseDate('not-a-date') === null && cadence.parseDate('2026-05-01') instanceof Date) {
pass('parseDate rejects malformed input and accepts ISO dates');
} else {
fail('parseDate validation wrong');
}
// Status normalization (strips bold + trailing date, lowercases, maps aliases)
if (cadence.normalizeStatus('**Applied** 2026-05-01') === 'applied') {
pass('normalizeStatus strips bold + trailing date and lowercases');
} else {
fail(`normalizeStatus produced ${cadence.normalizeStatus('**Applied** 2026-05-01')}`);
}
// Urgency decision tree (CADENCE defaults: applied_first=7, max_followups=2, responded_initial=1, interview_thankyou=1)
const urgencyCases = [
[['applied', 7, null, 0], 'overdue', 'applied past applied_first → overdue'],
[['applied', 3, null, 0], 'waiting', 'applied within window → waiting'],
[['applied', 30, null, 2], 'cold', 'applied at max follow-ups → cold'],
[['responded', 0, null, 0], 'urgent', 'responded before responded_initial → urgent'],
[['interview', 1, null, 0], 'overdue', 'interview past thank-you window → overdue'],
];
for (const [args, expected, label] of urgencyCases) {
const got = cadence.computeUrgency(...args);
if (got === expected) pass(`computeUrgency: ${label}`);
else fail(`computeUrgency ${label}: expected ${expected}, got ${got}`);
}
// Next follow-up date scheduling
const nextCases = [
[['applied', '2026-05-01', null, 0], '2026-05-08', 'first applied follow-up = appDate + applied_first'],
[['applied', '2026-05-01', null, 2], null, 'cold (max follow-ups) → null'],
[['interview', '2026-05-01', null, 0], '2026-05-02', 'interview = appDate + interview_thankyou'],
];
for (const [args, expected, label] of nextCases) {
const got = cadence.computeNextFollowupDate(...args);
if (got === expected) pass(`computeNextFollowupDate: ${label}`);
else fail(`computeNextFollowupDate ${label}: expected ${expected}, got ${got}`);
}
} catch (e) {
fail(`follow-up cadence module crashed: ${e.message}`);
}
// ── 12. PROVIDERS — Workable ────────────────────────────────────────
console.log('\n12. Provider — workable');
try {
const workable = (await import(pathToFileURL(join(ROOT, 'providers/workable.mjs')).href)).default;
const { parseWorkableMarkdown } = await import(pathToFileURL(join(ROOT, 'providers/workable.mjs')).href);
// detect() — auto-detection from careers_url
if (workable.id === 'workable') pass('workable.id is "workable"');
else fail(`workable.id is ${JSON.stringify(workable.id)}`);
const hit = workable.detect({ name: 'TestCo', careers_url: 'https://apply.workable.com/optimile' });
if (hit && hit.url === 'https://apply.workable.com/optimile/jobs.md') {
pass('workable.detect() resolves apply.workable.com/<slug> → /jobs.md feed');
} else {
fail(`workable.detect() returned ${JSON.stringify(hit)}`);
}
const miss = workable.detect({ name: 'TestCo', careers_url: 'https://example.com/careers' });
if (miss === null) pass('workable.detect() returns null for non-workable URLs');
else fail(`workable.detect() should return null, got ${JSON.stringify(miss)}`);
// parse() — markdown table
const sampleMd = [
'# Optimile — All Open Positions',
'',
'| Title | Department | Location | Type | Salary | Posted | Details |',
'|---|---|---|---|---|---|---|',
'| Senior AI PM | Product | Ghent, Belgium | Full-time | — | 2026-04-01 | [View](https://apply.workable.com/optimile/jobs/view/ABC123.md) |',
'| Tech Lead | Engineering | Remote | Full-time | — | 2026-03-25 | [View](https://apply.workable.com/optimile/jobs/view/DEF456.md) |',
].join('\n');
const jobs = parseWorkableMarkdown(sampleMd, 'Optimile');
if (jobs.length === 2) pass('parseWorkableMarkdown extracts 2 jobs from 2-row table');
else fail(`parseWorkableMarkdown returned ${jobs.length} jobs, expected 2`);
if (jobs[0]?.title === 'Senior AI PM' && jobs[0]?.location === 'Ghent, Belgium' && jobs[0]?.company === 'Optimile') {
pass('parseWorkableMarkdown extracts title, location, company correctly');
} else {
fail(`parseWorkableMarkdown row 0 = ${JSON.stringify(jobs[0])}`);
}
if (jobs[0]?.url === 'https://apply.workable.com/optimile/jobs/view/ABC123') {
pass('parseWorkableMarkdown strips .md suffix from job URL');
} else {
fail(`parseWorkableMarkdown should strip .md; got url=${JSON.stringify(jobs[0]?.url)}`);
}
// Robustness
if (parseWorkableMarkdown('', 'X').length === 0) pass('empty input → empty result');
else fail('empty input should yield empty result');
if (parseWorkableMarkdown(null, 'X').length === 0) pass('null input → empty result (no crash)');
else fail('null input should yield empty result without crashing');
// fetch() reaches the http context on the happy path (allowed hostname).
await workable.fetch(
{ name: 'Smoke', careers_url: 'https://apply.workable.com/optimile' },
{
transport: 'http',
fetchText: async (url) => {
if (!url.startsWith('https://apply.workable.com/')) {
throw new Error('fetchText called with unexpected URL');
}
return '| Title | Department | Location | Type | Salary | Posted | Details |\n|---|---|---|---|---|---|---|\n';
},
fetchJson: async () => { throw new Error('fetchJson should not be called'); },
},
);
pass('workable.fetch() reaches fetchText on the happy path (allowed hostname)');
// fetch() rejects an unresolvable careers_url (no apply.workable.com match in URL).
let rejected = false;
try {
await workable.fetch(
{ name: 'BadUrl', careers_url: 'https://evil.com/totally-not-workable' },
{
transport: 'http',
fetchText: async () => { throw new Error('SSRF! should not reach here'); },
fetchJson: async () => { throw new Error('SSRF! should not reach here'); },
},
);
} catch (e) {
if (e.message.includes('cannot derive feed URL')) {
rejected = true;
} else {
fail(`workable.fetch() rejected with wrong error: ${e.message}`);
}
}
if (rejected) pass('workable.fetch() rejects unresolvable careers_url before fetch');
else fail('workable.fetch() should throw cannot-derive-feed-URL for non-Workable URLs');
// SSRF: malicious URL with apply.workable.com in the PATH (not hostname) must not be detected as Workable.
// With strict URL parsing, the hostname `evil.example` fails the check and detect() returns null.
if (workable.detect({ name: 'Spoof', careers_url: 'https://evil.example/apply.workable.com/slug' }) === null) {
pass('workable.detect() rejects path-spoofed URLs (apply.workable.com in path, not hostname)');
} else {
fail('workable.detect() must NOT misdetect URLs that contain apply.workable.com in the path');
}
// careers_url with non-string value (e.g. YAML mistake passing a number) → detect() returns null without crashing
if (workable.detect({ name: 'X', careers_url: 42 }) === null) {
pass('workable.detect() returns null for non-string careers_url (42)');
} else {
fail('workable.detect() should treat non-string careers_url as missing');
}
// Workable parser tolerates a title with a stray pipe — URL is extracted from the line, not cols[7]
const strayPipeMd = [
'| Title | Department | Location | Type | Salary | Posted | Details |',
'|---|---|---|---|---|---|---|',
'| Senior PM (full | part-time) | Product | Remote | Full-time | — | 2026-04-01 | [View](https://apply.workable.com/x/jobs/view/PIPE.md) |',
].join('\n');
const strayJobs = parseWorkableMarkdown(strayPipeMd, 'X');
if (strayJobs.length === 1 && strayJobs[0].url === 'https://apply.workable.com/x/jobs/view/PIPE') {
pass('parseWorkableMarkdown extracts URL from line-level regex (survives stray pipes in title)');
} else {
fail(`stray-pipe row not handled correctly: ${JSON.stringify(strayJobs)}`);
}
// Off-domain [View] link is dropped (URL validation)
const offDomainMd = [
'| Title | Department | Location | Type | Salary | Posted | Details |',
'|---|---|---|---|---|---|---|',
'| Good Role | Product | Remote | Full-time | — | 2026-04-01 | [View](https://apply.workable.com/x/jobs/view/ABC.md) |',
'| Evil Role | Product | Remote | Full-time | — | 2026-04-01 | [View](https://evil.example/jobs/view/X) |',
'| Insecure Role | Product | Remote | Full-time | — | 2026-04-01 | [View](http://apply.workable.com/x/jobs/view/Y.md) |',
].join('\n');
const filteredJobs = parseWorkableMarkdown(offDomainMd, 'X');
if (filteredJobs.length === 1 && filteredJobs[0].title === 'Good Role') {
pass('parseWorkableMarkdown drops off-domain and non-https [View] links');
} else {
fail(`expected only "Good Role" through, got ${JSON.stringify(filteredJobs.map(j => j.title))}`);
}
} catch (e) {
fail(`workable provider tests crashed: ${e.message}`);
}
// ── 13. PROVIDERS — SmartRecruiters ─────────────────────────────────
console.log('\n13. Provider — smartrecruiters');
try {
const sr = (await import(pathToFileURL(join(ROOT, 'providers/smartrecruiters.mjs')).href)).default;
const { parseSmartRecruitersResponse } = await import(pathToFileURL(join(ROOT, 'providers/smartrecruiters.mjs')).href);
if (sr.id === 'smartrecruiters') pass('smartrecruiters.id is "smartrecruiters"');
else fail(`smartrecruiters.id is ${JSON.stringify(sr.id)}`);
const hitCareers = sr.detect({ name: 'Adyen', careers_url: 'https://careers.smartrecruiters.com/adyen' });
if (hitCareers && hitCareers.url.startsWith('https://api.smartrecruiters.com/v1/companies/adyen/postings')) {
pass('smartrecruiters.detect() resolves careers.smartrecruiters.com/<slug> → api URL');
} else {
fail(`smartrecruiters.detect(careers) returned ${JSON.stringify(hitCareers)}`);
}
const hitJobs = sr.detect({ name: 'X', careers_url: 'https://jobs.smartrecruiters.com/x' });
if (hitJobs && hitJobs.url.startsWith('https://api.smartrecruiters.com/v1/companies/x/postings')) {
pass('smartrecruiters.detect() also handles jobs.smartrecruiters.com');
} else {
fail(`smartrecruiters.detect(jobs) returned ${JSON.stringify(hitJobs)}`);
}
if (sr.detect({ name: 'X', careers_url: 'https://example.com/careers' }) === null) {
pass('smartrecruiters.detect() returns null for non-SR URLs');
} else {
fail('smartrecruiters.detect() should return null for non-SR URLs');
}
// parseSmartRecruitersResponse
const sample = {
content: [
{
id: 'abc-123',
name: 'Senior PM',
ref: 'https://api.smartrecruiters.com/v1/companies/sgs/postings/abc-123',
location: { fullLocation: 'Geneva, Switzerland', remote: false },
},
{
id: 'def-456',
name: 'Remote AI Engineer',
ref: 'https://api.smartrecruiters.com/v1/companies/sgs/postings/def-456',
location: { city: 'Paris', country: 'France', remote: true },
},
{
id: 'ghi-789',
name: 'No-ref Role',
location: { fullLocation: 'Berlin, Germany' },
},
],
};
const jobs = parseSmartRecruitersResponse(sample, 'SGS');
if (jobs.length === 3) pass('parseSmartRecruitersResponse extracts 3 jobs');
else fail(`parseSmartRecruitersResponse returned ${jobs.length} jobs`);
if (jobs[0]?.location === 'Geneva, Switzerland' && jobs[0]?.title === 'Senior PM') {
pass('parseSmartRecruitersResponse uses fullLocation when present');
} else {
fail(`row 0 = ${JSON.stringify(jobs[0])}`);
}
if (jobs[1]?.location === 'Paris, France, Remote') {
pass('parseSmartRecruitersResponse builds location from city/country/remote when no fullLocation');
} else {
fail(`row 1 location = ${JSON.stringify(jobs[1]?.location)}, expected "Paris, France, Remote"`);
}
if (jobs[0]?.url === 'https://jobs.smartrecruiters.com/sgs/postings/abc-123') {
pass('parseSmartRecruitersResponse rewrites api.smartrecruiters.com → jobs.smartrecruiters.com');
} else {
fail(`row 0 url = ${JSON.stringify(jobs[0]?.url)}`);
}
if (jobs[2]?.url && jobs[2].url.startsWith('https://jobs.smartrecruiters.com/sgs/ghi-789')) {
pass('parseSmartRecruitersResponse falls back to synthetic URL when ref is missing');
} else {
fail(`row 2 url = ${JSON.stringify(jobs[2]?.url)}`);
}
// Empty input safety
if (parseSmartRecruitersResponse({}, 'X').length === 0) pass('empty {} input → empty result');
else fail('empty {} input should yield empty result');
if (parseSmartRecruitersResponse({ content: 'not an array' }, 'X').length === 0) {
pass('non-array content → empty result (no crash)');
} else {
fail('non-array content should yield empty result');
}
// careers_url with non-string value → detect() returns null without crashing
if (sr.detect({ name: 'X', careers_url: { foo: 'bar' } }) === null) {
pass('smartrecruiters.detect() returns null for non-string careers_url (object)');
} else {
fail('smartrecruiters.detect() should treat non-string careers_url as missing');
}
// Fallback URL when both ref AND id are missing → empty string (not "undefined" in URL)
const noRefNoId = parseSmartRecruitersResponse(
{ content: [{ name: 'Stranded Role' }] },
'X',
);
if (noRefNoId.length === 1 && noRefNoId[0].url === '') {
pass('parseSmartRecruitersResponse returns url="" when both ref and id are missing');
} else {
fail(`expected url='' when ref+id both missing, got ${JSON.stringify(noRefNoId[0])}`);
}
// SSRF: malicious URL with smartrecruiters hostname in the PATH (not host) must not be detected.
if (sr.detect({ name: 'Spoof', careers_url: 'https://evil.example/careers.smartrecruiters.com/slug' }) === null) {
pass('smartrecruiters.detect() rejects path-spoofed URLs');
} else {
fail('smartrecruiters.detect() must NOT misdetect path-spoofed URLs');
}
// SmartRecruiters: untrusted j.ref host falls through to fallback rather than rewriting
const bogusRef = parseSmartRecruitersResponse(
{ content: [{ id: 'X1', name: 'Strange Role', ref: 'https://evil.example/v1/companies/x/postings/X1' }] },
'TestCo',
);
if (bogusRef[0]?.url && !bogusRef[0].url.includes('evil.example')) {
pass('parseSmartRecruitersResponse rejects untrusted j.ref host (falls through to fallback)');
} else {
fail(`untrusted j.ref leaked into url: ${JSON.stringify(bogusRef[0]?.url)}`);
}
// SmartRecruiters: companyName with spaces/symbols is slugified for the fallback URL
const slugifiedCompany = parseSmartRecruitersResponse(
{ content: [{ id: 'X2', name: 'Strange Role' }] },
'My Acme & Co.',
);
if (slugifiedCompany[0]?.url === 'https://jobs.smartrecruiters.com/my-acme-co/X2-strange-role') {
pass('parseSmartRecruitersResponse slugifies the companyName for the fallback URL');
} else {
fail(`fallback URL not properly slugified: ${JSON.stringify(slugifiedCompany[0]?.url)}`);
}
// Pagination: fetch() loops until an empty page (or short page) is returned
let pageRequests = 0;
const pagedJobs = await sr.fetch(
{ name: 'PagedCo', careers_url: 'https://careers.smartrecruiters.com/paged' },
{
transport: 'http',
fetchText: async () => { throw new Error('fetchText should not be called'); },
fetchJson: async (url) => {
pageRequests++;
const offset = parseInt(new URL(url).searchParams.get('offset') || '0', 10);
if (offset === 0) {
// Page 1: full page (100 items)
return { content: Array.from({ length: 100 }, (_, i) => ({ id: `P1-${i}`, name: `Role 1-${i}` })) };
}
if (offset === 100) {
// Page 2: short page (50 items) → loop stops after this
return { content: Array.from({ length: 50 }, (_, i) => ({ id: `P2-${i}`, name: `Role 2-${i}` })) };
}
// Should not be reached because page 2 was short
return { content: [] };
},
},
);
if (pageRequests === 2 && pagedJobs.length === 150) {
pass('smartrecruiters.fetch() paginates and aggregates results (2 pages → 150 total)');
} else {
fail(`pagination: pageRequests=${pageRequests}, total=${pagedJobs.length} (expected 2 requests / 150 results)`);
}
// Pagination stop condition: empty content terminates the loop
let emptyPageRequests = 0;
const emptyJobs = await sr.fetch(
{ name: 'EmptyCo', careers_url: 'https://careers.smartrecruiters.com/empty' },
{
transport: 'http',
fetchText: async () => { throw new Error('fetchText should not be called'); },
fetchJson: async () => {
emptyPageRequests++;
return { content: [] };
},
},
);
if (emptyPageRequests === 1 && emptyJobs.length === 0) {
pass('smartrecruiters.fetch() stops on the first empty page');
} else {
fail(`empty pagination: requests=${emptyPageRequests}, total=${emptyJobs.length}`);
}
} catch (e) {
fail(`smartrecruiters provider tests crashed: ${e.message}`);
}
// ── 14. PROVIDERS — Recruitee ───────────────────────────────────────
console.log('\n14. Provider — recruitee');
try {
const recruitee = (await import(pathToFileURL(join(ROOT, 'providers/recruitee.mjs')).href)).default;
const { parseRecruiteeResponse } = await import(pathToFileURL(join(ROOT, 'providers/recruitee.mjs')).href);
if (recruitee.id === 'recruitee') pass('recruitee.id is "recruitee"');
else fail(`recruitee.id is ${JSON.stringify(recruitee.id)}`);
const hit = recruitee.detect({ name: 'Channable', careers_url: 'https://channable.recruitee.com' });
if (hit && hit.url === 'https://channable.recruitee.com/api/offers/') {
pass('recruitee.detect() resolves <slug>.recruitee.com → api offers');
} else {
fail(`recruitee.detect() returned ${JSON.stringify(hit)}`);
}
if (recruitee.detect({ name: 'X', careers_url: 'https://example.com/careers' }) === null) {
pass('recruitee.detect() returns null for non-recruitee URLs');
} else {
fail('recruitee.detect() should return null for non-recruitee URLs');
}
// parseRecruiteeResponse
const sample = {
offers: [
{ title: 'Senior PM', careers_url: 'https://channable.recruitee.com/o/senior-pm', city: 'Utrecht', country: 'Netherlands', remote: false },
{ title: 'Backend Eng', url: 'https://channable.recruitee.com/o/backend', city: 'Amsterdam', country: 'Netherlands', remote: true },
{ title: 'AI Lead', location: 'Remote, EMEA' },
],
};
const jobs = parseRecruiteeResponse(sample, 'Channable');
if (jobs.length === 3) pass('parseRecruiteeResponse extracts 3 offers');
else fail(`parseRecruiteeResponse returned ${jobs.length} offers`);
if (jobs[0]?.title === 'Senior PM' && jobs[0]?.company === 'Channable' && jobs[0]?.url === 'https://channable.recruitee.com/o/senior-pm') {
pass('parseRecruiteeResponse prefers careers_url field over url');
} else {
fail(`row 0 = ${JSON.stringify(jobs[0])}`);
}
if (jobs[1]?.location === 'Amsterdam, Netherlands, Remote') {
pass('parseRecruiteeResponse assembles city/country/remote when no location field');
} else {
fail(`row 1 location = ${JSON.stringify(jobs[1]?.location)}, expected "Amsterdam, Netherlands, Remote"`);
}
if (jobs[2]?.location === 'Remote, EMEA') {
pass('parseRecruiteeResponse uses explicit location field when present');
} else {
fail(`row 2 location = ${JSON.stringify(jobs[2]?.location)}`);
}
if (parseRecruiteeResponse({}, 'X').length === 0) pass('empty {} → empty result');
else fail('empty {} should yield empty result');
if (parseRecruiteeResponse({ offers: null }, 'X').length === 0) {
pass('null offers → empty result (no crash)');
} else {
fail('null offers should yield empty result');
}
// careers_url with non-string value → detect() returns null without crashing
if (recruitee.detect({ name: 'X', careers_url: null }) === null && recruitee.detect({ name: 'X', careers_url: 7 }) === null) {
pass('recruitee.detect() returns null for non-string careers_url (null and 7)');
} else {
fail('recruitee.detect() should treat non-string careers_url as missing');
}
// SSRF: malicious URL with recruitee.com in the PATH (not host) must not be detected.
if (recruitee.detect({ name: 'Spoof', careers_url: 'https://evil.example/channable.recruitee.com/foo' }) === null) {
pass('recruitee.detect() rejects path-spoofed URLs');
} else {
fail('recruitee.detect() must NOT misdetect path-spoofed URLs');
}
// Off-domain offer URL is dropped (URL validation)
const offDomainOffers = parseRecruiteeResponse(
{
offers: [