{"record":{"id":"dca28d2c632d4fa2","repo":"microsoft/TypeScript","slug":"the-baseline-file-relativefilename-has-changed","errorCode":null,"errorMessage":"The baseline file ${relativeFileName} has changed. (Run \"hereby baseline-accept\" if the new baseline is correct.)","messagePattern":"The baseline file (.+?) has changed\\. \\(Run \"hereby baseline-accept\" if the new baseline is correct\\.\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/harness/harnessIO.ts","lineNumber":1486,"sourceCode":"        createDirectoryStructure(IO.directoryName(actualFileName)!); // TODO: GH#18217\r\n\r\n        // Delete the actual file in case it fails\r\n        if (IO.fileExists(actualFileName)) {\r\n            IO.deleteFile(actualFileName);\r\n        }\r\n\r\n        const encodedActual = Utils.encodeString(actual);\r\n        if (expected !== encodedActual) {\r\n            if (actual === noContent) {\r\n                IO.writeFile(actualFileName + \".delete\", \"\");\r\n            }\r\n            else {\r\n                IO.writeFile(actualFileName, encodedActual);\r\n            }\r\n            const errorMessage = getBaselineFileChangedErrorMessage(relativeFileName);\r\n            if (opts && opts.PrintDiff) {\r\n                const patch = Diff.createTwoFilesPatch(\"Expected\", \"Actual\", expected, actual, \"The current baseline\", \"The new version\");\r\n                throw new Error(`${errorMessage}${ts.ForegroundColorEscapeSequences.Grey}\\n\\n${patch}`);\r\n            }\r\n            else {\r\n                if (!IO.fileExists(expected)) {\r\n                    throw new Error(`New baseline created at ${IO.joinPath(\"tests\", \"baselines\", \"local\", relativeFileName)}`);\r\n                }\r\n                else {\r\n                    throw new Error(errorMessage);\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    function getBaselineFileChangedErrorMessage(relativeFileName: string): string {\r\n        return `The baseline file ${relativeFileName} has changed. (Run \"hereby baseline-accept\" if the new baseline is correct.)`;\r\n    }\r\n\r\n    export function runBaseline(relativeFileName: string, actual: string | null, opts?: BaselineOptions): void { // eslint-disable-line no-restricted-syntax\r\n        const actualFileName = localPath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);\r","sourceCodeStart":1468,"sourceCodeEnd":1504,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/harness/harnessIO.ts#L1468-L1504","documentation":"Thrown by writeComparison (harnessIO.ts:1486) when a baseline test's actual output differs from the recorded reference and BaselineOptions.PrintDiff is set. The full unified diff is appended to the message via Diff.createTwoFilesPatch. The actual file is written under tests/baselines/local for inspection.","triggerScenarios":"A test that calls runBaseline/runMultifileBaseline produces content that no longer byte-matches the committed file under tests/baselines/reference, and the harness is configured with PrintDiff. Common after a real behavior change in the compiler or after editing a test's inputs.","commonSituations":"Intentional compiler behavior change (e.g. a diagnostic rewrite, new emit format); updating lib.d.ts; changing pretty-printing; any PR that legitimately alters output — the reference baseline must be regenerated.","solutions":["Read the diff in the error message; if the new output is correct, run `hereby baseline-accept` to promote tests/baselines/local → tests/baselines/reference.","If the diff is unexpected, revert the source change that caused it or fix the compiler regression before accepting.","Re-run just the failing test (`hereby <test-task> --fix`) to confirm the new local file matches what you intend to accept.","Commit the regenerated reference baselines together with the code change in the same atomic commit."],"exampleFix":"# before — test fails because reference is stale\n$ hereby test-compiler\nError: The baseline file ... has changed.\n\n# after — accept the intended change\n$ hereby baseline-accept\n$ hereby test-compiler   # now green","handlingStrategy":"validation","validationCode":"// In CI, detect drift and fail with a dedicated exit code instead of a raw throw.\nconst expected = IO.readFile(referencePath);\nif (expected !== undefined && expected !== Utils.encodeString(actual)) {\n  console.error(`Baseline drift in ${relativeFileName}. Run: hereby baseline-accept`);\n  process.exit(BASELINE_DRIFT_EXIT_CODE);\n}","typeGuard":null,"tryCatchPattern":"try {\n  runBaseline(relativeFileName, actual, { PrintDiff: true });\n} catch (e) {\n  if (e.message.includes('baseline file') && e.message.includes('baseline-accept')) {\n    // surface a CI-friendly hint, then re-throw or mark the test as baseline-pending\n    throw Object.assign(new Error('BASELINE_DRIFT: ' + e.message), { baselineDrift: true });\n  }\n  throw e;\n}","preventionTips":["Always commit regenerated reference baselines atomically with the code change that caused them.","Run the full baseline suite locally before pushing so drift is caught early.","Treat baseline changes as part of code review — read the diff before accepting."],"tags":["test-harness","baseline","diff","regression"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}