|
| 1 | +import { expect, test, describe } from "bun:test"; |
| 2 | +import { readFileSync } from "fs"; |
| 3 | +import { join } from "path"; |
| 4 | + |
| 5 | +describe("Experiments TSV Consistency Test", () => { |
| 6 | + const v4Path = join(import.meta.dir, "..", "v4.0-alpha.md"); |
| 7 | + const autoResearchPath = join(import.meta.dir, "..", "Algorithm-Autoresearch.md"); |
| 8 | + |
| 9 | + const v4Content = readFileSync(v4Path, "utf-8"); |
| 10 | + const autoResearchContent = readFileSync(autoResearchPath, "utf-8"); |
| 11 | + |
| 12 | + test("1) 6 columns same in both files", () => { |
| 13 | + // Look for the header row: iteration commit metric delta status description |
| 14 | + // In v4.0-alpha.md: |
| 15 | + const v4HeaderMatch = v4Content.match(/iteration\tcommit\tmetric\tdelta\tstatus\tdescription/); |
| 16 | + expect(v4HeaderMatch).toBeTruthy(); |
| 17 | + |
| 18 | + // In Algorithm-Autoresearch.md: |
| 19 | + const arHeaderMatch = autoResearchContent.match(/iteration \| commit \| metric \| delta \| status \| description/); |
| 20 | + expect(arHeaderMatch).toBeTruthy(); |
| 21 | + }); |
| 22 | + |
| 23 | + test("2) Status values: baseline,keep,discard,crash,skip", () => { |
| 24 | + // In v4.0-alpha.md |
| 25 | + const v4StatusMatch = v4Content.match(/`status` = `baseline \| keep \| discard \| crash \| skip`/); |
| 26 | + expect(v4StatusMatch).toBeTruthy(); |
| 27 | + |
| 28 | + // In Algorithm-Autoresearch.md |
| 29 | + // Since there are no explicit listed status rules in AutoResearch like v4.0-alpha, |
| 30 | + // let's verify if 'status' has 'baseline', 'keep', 'discard', 'crash', 'skip' implicitly |
| 31 | + // in the document via phase decriptions and delta rules. |
| 32 | + const arStatusMatch = autoResearchContent.match(/baseline/i) && |
| 33 | + autoResearchContent.match(/keep/i) && |
| 34 | + autoResearchContent.match(/discard/i) && |
| 35 | + autoResearchContent.match(/crash/i) && |
| 36 | + autoResearchContent.match(/skip/i); |
| 37 | + expect(arStatusMatch).toBeTruthy(); |
| 38 | + }); |
| 39 | + |
| 40 | + test("3) Delta calc rule consistent", () => { |
| 41 | + // In v4.0-alpha.md |
| 42 | + const v4DeltaMatch = v4Content.match(/`delta` = change from most recent `keep` or `baseline` row \(ignore `discard`\/`crash`\/`skip` rows\)/); |
| 43 | + expect(v4DeltaMatch).toBeTruthy(); |
| 44 | + |
| 45 | + // In Algorithm-Autoresearch.md |
| 46 | + const arDeltaMatch = autoResearchContent.match(/delta = change from most recent keep\/baseline \(ignore discard\/crash\/skip\)/); |
| 47 | + expect(arDeltaMatch).toBeTruthy(); |
| 48 | + }); |
| 49 | + |
| 50 | + test("4) Context Recovery references TSV", () => { |
| 51 | + // v4.0-alpha.md: |
| 52 | + const v4RecoveryMatch = v4Content.match(/If `\[Q\]` criteria were used, check for `experiments\.tsv` in the PRD directory/i); |
| 53 | + expect(v4RecoveryMatch).toBeTruthy(); |
| 54 | + |
| 55 | + // Algorithm-Autoresearch.md: |
| 56 | + const arRecoveryMatch = autoResearchContent.match(/Context Recovery \(during Autoresearch\)[\s\S]*?recover sub-loop state by reading experiments\.tsv:/i); |
| 57 | + expect(arRecoveryMatch).toBeTruthy(); |
| 58 | + }); |
| 59 | + |
| 60 | + test("5) Re-entry in TSV header", () => { |
| 61 | + // Algorithm-Autoresearch.md explicitly mentions this: |
| 62 | + const arReentryMatch = autoResearchContent.match(/Track re-entry count in experiments\.tsv header comment:\s*`# think_reentries: N`/i); |
| 63 | + expect(arReentryMatch).toBeTruthy(); |
| 64 | + |
| 65 | + // It also mentions it in Context Recovery: "# think_reentries: N" |
| 66 | + const arContextRecoveryReentryMatch = autoResearchContent.match(/Re-entry count:\*\* `# think_reentries: N` header comment/i); |
| 67 | + expect(arContextRecoveryReentryMatch).toBeTruthy(); |
| 68 | + }); |
| 69 | +}); |
0 commit comments