Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/test_provider_ternary_freeze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Paso 6.a: freeze provider ternaries in ui/src so they cannot grow."""
from __future__ import annotations

from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "ui" / "src"

MINIMAX_TERNARY = "=== 'minimax' ?"
MAESTRO_WRITER = "writingProvider === 'maestro'"
MAX_MINIMAX_TERNARIES = 30
MAX_MAESTRO_WRITERS = 6


def _count_literal(needle: str) -> int:
total = 0
for path in SRC.rglob("*"):
if path.suffix not in {".ts", ".tsx"}:
continue
total += path.read_text(encoding="utf-8").count(needle)
return total


def test_minimax_ternaries_under_ui_src_do_not_increase() -> None:
found = _count_literal(MINIMAX_TERNARY)
assert found <= MAX_MINIMAX_TERNARIES, (
f"{MINIMAX_TERNARY!r} under ui/src grew to {found}; cap is "
f"{MAX_MINIMAX_TERNARIES}. Map new cases through provider_profile / "
"writingProviderFromText instead of adding ternaries."
)


def test_maestro_writing_provider_comparisons_do_not_increase() -> None:
found = _count_literal(MAESTRO_WRITER)
assert found <= MAX_MAESTRO_WRITERS, (
f"{MAESTRO_WRITER!r} under ui/src grew to {found}; cap is "
f"{MAX_MAESTRO_WRITERS}. Use the canonical writing-provider mapper."
)
43 changes: 43 additions & 0 deletions ui/tests/providerTernaryFreeze.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import { extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'

const SRC = fileURLToPath(new URL('../src', import.meta.url))
const MINIMAX_TERNARY = "=== 'minimax' ?"
const MAESTRO_WRITER = "writingProvider === 'maestro'"
const MAX_MINIMAX_TERNARIES = 30
const MAX_MAESTRO_WRITERS = 6

function walk(dir) {
const files = []
for (const name of readdirSync(dir)) {
const path = join(dir, name)
if (statSync(path).isDirectory()) files.push(...walk(path))
else if (extname(path) === '.ts' || extname(path) === '.tsx') files.push(path)
}
return files
}

function countLiteral(needle) {
return walk(SRC).reduce((total, path) => (
total + readFileSync(path, 'utf8').split(needle).length - 1
), 0)
}

test('ui/src does not grow === \'minimax\' ? ternaries', () => {
const found = countLiteral(MINIMAX_TERNARY)
assert.ok(
found <= MAX_MINIMAX_TERNARIES,
`${MINIMAX_TERNARY} under ui/src grew to ${found}; cap is ${MAX_MINIMAX_TERNARIES}`,
)
})

test('ui/src does not grow writingProvider === \'maestro\' comparisons', () => {
const found = countLiteral(MAESTRO_WRITER)
assert.ok(
found <= MAX_MAESTRO_WRITERS,
`${MAESTRO_WRITER} under ui/src grew to ${found}; cap is ${MAX_MAESTRO_WRITERS}`,
)
})
Loading