Files
orca/mobile/src/test-support/census-source-files.test.ts
T
Neil 6e1b7e7fa3 test: remove junk tests that assert source text instead of behavior (#23815)
Deletes 101 test files and trims 112 more, all matching documented junk
patterns: exact source/import/string greps, copied inventories and export
lists, duplicate invocations of a contract another test already owns,
typeof-shape checks TypeScript already enforces, and self-comparisons.

The largest group read a production `.ts` file and asserted on its text —
for example a TaskPage test that required the source to contain
`selectedRepos.find((r) => r.id === newIssueRepoId) ?? selectedRepos[0] ?? null`.
Any behavior-preserving rename broke it; no behavior change ever did.

Production-side follow-through: exports that only these tests imported are
de-exported or deleted, stale comments pointing at removed censuses are
dropped, and the reliability-gate registry, `cloud/package.json` test lists,
and orphaned source-reading helpers are updated so nothing references a
deleted file.

Two files kept their real coverage and lost only the census scaffolding:
`agent-status-producer-census.test.ts` now drives all five producers end to
end instead of grepping the source tree, and `config-toml-trust-stale-writes`
replaces an export-list parity check.
2026-09-29 01:21:53 -07:00

78 lines
3.4 KiB
TypeScript

import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join, relative } from 'node:path'
import { fileURLToPath } from 'node:url'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { censusSourceFiles, isGeneratedSource } from './census-source-files'
const mobileRoot = fileURLToPath(new URL('../..', import.meta.url))
let scratch = ''
beforeEach(() => {
scratch = mkdtempSync(join(tmpdir(), 'orca-census-source-files-'))
})
afterEach(() => {
rmSync(scratch, { recursive: true, force: true })
})
function plant(relativePath: string, source: string): void {
const absolute = join(scratch, relativePath)
mkdirSync(join(absolute, '..'), { recursive: true })
writeFileSync(absolute, source, 'utf8')
}
describe('the source files a census reads', () => {
it('leaves out build output that would be read as a violating import', () => {
// The shape that started this: a generated file whose text holds exactly what a census is
// looking for. Every one of them is minified vendor output, so the match is a token in
// somebody else's code and the census has no line to offer anybody.
const violating = "import { requiredString } from '../../src/shared/rpc-contract/params'\n"
plant('src/components/engine.generated.ts', violating)
plant('src/components/Diagram.tsx', violating)
const walked = censusSourceFiles(join(scratch, 'src')).map((path) => relative(scratch, path))
expect(walked).toEqual([join('src', 'components', 'Diagram.tsx')])
// Both halves: the generated file is gone, and the file beside it carrying the same text is
// not — a walk that returned nothing at all would satisfy the first line on its own.
expect(readFileSync(join(scratch, 'src/components/engine.generated.ts'), 'utf8')).toBe(
violating
)
})
it('leaves out node_modules, and keeps everything else', () => {
plant('src/a.ts', '')
plant('src/node_modules/dep/index.ts', '')
plant('src/deep/b.tsx', '')
plant('src/notes.md', '')
expect(
censusSourceFiles(join(scratch, 'src'))
.map((path) => relative(scratch, path))
.sort()
).toEqual([join('src', 'a.ts'), join('src', 'deep', 'b.tsx'), join('src', 'notes.md')].sort())
})
it('names build output by the suffix the generators write, and nothing else', () => {
expect(isGeneratedSource('mermaid-page-engine.generated.ts')).toBe(true)
expect(isGeneratedSource('route-manifest.generated.tsx')).toBe(true)
expect(isGeneratedSource('generated.ts')).toBe(false)
expect(isGeneratedSource('rpc-client.ts')).toBe(false)
expect(isGeneratedSource('generated-goldens.ts')).toBe(false)
})
it('covers every artifact the tree generates, read from the ignore file that lists them', () => {
// The list is `mobile/.gitignore`, because that is what the generators and the build agree on.
// A seventh artifact landing under a name this predicate does not match would put a multi-megabyte
// vendor bundle back into every census, which is the failure this module exists for.
const ignored = readFileSync(join(mobileRoot, '.gitignore'), 'utf8')
.split('\n')
.map((line) => line.trim())
.filter((line) => line.endsWith('.generated.ts'))
expect(ignored.length).toBeGreaterThanOrEqual(5)
for (const entry of ignored) {
expect(isGeneratedSource(entry), entry).toBe(true)
}
})
})