textmachine/platform/internal/ingest/notes_test.go

72 lines
3 KiB
Go

package ingest
import "testing"
// notes_test.go pins the seam's most quietly dangerous map: what a reader is told about a flagged
// pair. It had no test at all, and its whole purpose is that a word of the engine's never reaches a
// client.
// Every reason of appendix A answers ITS code, and no engine word survives the crossing.
//
// Mutation caught: dropping a row; forwarding `reason` verbatim; renaming a code.
func TestEveryEngineReasonAnswersTheContractCodeOfAppendixA(t *testing.T) {
for reason, want := range map[string]string{
"hard_refusal": "content_withheld", "soft_refusal": "content_withheld",
"content_filter": "content_withheld", "hard_block": "content_withheld",
"cjk_artifact": "source_residue", "excision_suspect": "text_possibly_dropped",
"coverage_fail": "incomplete_coverage", "sanitizer_defect": "markup_defect",
"loop_degenerate": "repetition", "decode_error": "unreadable_answer",
"glossary_miss": "term_not_applied", "length": "length_mismatch",
"empty": "empty_answer", "sanitizer_stripped": "markup_cleaned",
"upstream_not_ok": "unavailable",
} {
code, step := NoteCode(reason)
if code != want {
t.Errorf("%s answers %q, want %q", reason, code, want)
}
if code == reason {
t.Errorf("%s crossed the seam verbatim", reason)
}
if step != StepAttention && step != StepGlance {
t.Errorf("%s answers step %q, which is not a contract value", reason, step)
}
}
}
// A reason this build has never heard of gets the stable placeholder rather than the producer's own
// word — the window between two independent releases (PD-246).
func TestAReasonOutsideTheMapAnswersTheStablePlaceholder(t *testing.T) {
code, step := NoteCode("a_reason_invented_after_this_build")
if code != NoteCodeUnspecified {
t.Errorf("an unknown reason answered %q", code)
}
if step != StepGlance {
t.Errorf("an unknown reason answered step %q, want the quiet one", step)
}
if empty, _ := NoteCode(""); empty != NoteCodeUnspecified {
t.Errorf("an empty reason answered %q", empty)
}
}
// Every row's STEP is pinned, not just its code: a typo in one of the fifteen sends a withheld
// answer to the reader as a minor remark, and the reader skips a chapter that has no translation.
//
// Mutation caught: moving any row between the two steps.
func TestEveryReasonAnswersItsOwnStep(t *testing.T) {
for reason, want := range map[string]string{
"hard_refusal": StepAttention, "soft_refusal": StepAttention,
"content_filter": StepAttention, "hard_block": StepAttention,
"cjk_artifact": StepAttention, "excision_suspect": StepAttention,
"coverage_fail": StepAttention, "sanitizer_defect": StepAttention,
"loop_degenerate": StepAttention, "decode_error": StepAttention,
"empty": StepAttention, "upstream_not_ok": StepAttention,
"glossary_miss": StepGlance, "length": StepGlance, "sanitizer_stripped": StepGlance,
} {
if _, step := NoteCode(reason); step != want {
t.Errorf("%s answers step %q, want %q", reason, step, want)
}
}
if len(notes) != 15 {
t.Errorf("appendix A has fifteen reasons, the map has %d", len(notes))
}
}