66 editDistance ,
77 hashNormalizedText ,
88 resolveWithClassification ,
9+ StalenessStatus ,
10+ StalenessTier ,
911} from "./staleness" ;
1012
1113test ( "editDistance is 0 for identical strings" , ( ) => {
@@ -41,24 +43,24 @@ test("hashNormalizedText differs on a real word change", () => {
4143
4244test ( "checkTextStaleness Tier 0: cosmetic-only change (punctuation/whitespace) is fresh" , ( ) => {
4345 const result = checkTextStaleness ( "שלום, עולם!" , "שלום עולם" ) ;
44- expect ( result ) . toEqual ( { status : "fresh" , tier : 0 } ) ;
46+ expect ( result ) . toEqual ( { status : StalenessStatus . Fresh , tier : StalenessTier . Fingerprint } ) ;
4547} ) ;
4648
4749test ( "checkTextStaleness Tier 1: small real edit under the cosmetic threshold is fresh" , ( ) => {
4850 const stored = "a" . repeat ( 100 ) ;
4951 const current = `${ "a" . repeat ( 97 ) } bbb` ; // ~3% edit ratio once padded — see ratio math below
5052 const result = checkTextStaleness ( stored , current , DEFAULT_STALENESS_THRESHOLDS ) ;
51- expect ( result . tier ) . toBe ( 1 ) ;
52- expect ( result . status ) . toBe ( "fresh" ) ;
53+ expect ( result . tier ) . toBe ( StalenessTier . EditDistance ) ;
54+ expect ( result . status ) . toBe ( StalenessStatus . Fresh ) ;
5355 expect ( result . editRatio ) . toBeLessThanOrEqual ( DEFAULT_STALENESS_THRESHOLDS . cosmeticMaxRatio ) ;
5456} ) ;
5557
5658test ( "checkTextStaleness Tier 2: mid-range edit needs classification" , ( ) => {
5759 const stored = "The quick brown fox jumps over the lazy dog and keeps running" ;
5860 const current = "The quick brown fox leaps over the lazy dog and keeps walking" ;
5961 const result = checkTextStaleness ( stored , current , DEFAULT_STALENESS_THRESHOLDS ) ;
60- expect ( result . status ) . toBe ( "needsClassification" ) ;
61- expect ( result . tier ) . toBe ( 2 ) ;
62+ expect ( result . status ) . toBe ( StalenessStatus . NeedsClassification ) ;
63+ expect ( result . tier ) . toBe ( StalenessTier . AgenticClassification ) ;
6264 expect ( result . editRatio ) . toBeGreaterThan ( DEFAULT_STALENESS_THRESHOLDS . cosmeticMaxRatio ) ;
6365 expect ( result . editRatio ) . toBeLessThan ( DEFAULT_STALENESS_THRESHOLDS . structuralMinRatio ) ;
6466} ) ;
@@ -69,20 +71,19 @@ test("checkTextStaleness Tier 3: large rewrite is stale without classification",
6971 "Completely different content that shares almost nothing with before." ,
7072 DEFAULT_STALENESS_THRESHOLDS ,
7173 ) ;
72- expect ( result . status ) . toBe ( "stale" ) ;
73- expect ( result . tier ) . toBe ( 3 ) ;
74+ expect ( result . status ) . toBe ( StalenessStatus . Stale ) ;
75+ expect ( result . tier ) . toBe ( StalenessTier . StructuralBreak ) ;
7476} ) ;
7577
7678test ( "resolveWithClassification marks stillValid as fresh at tier 2" , ( ) => {
7779 const pending = checkTextStaleness (
7880 "The quick brown fox jumps over the lazy dog and keeps running" ,
79- "The quick brown fox leaps over the lazy dog and keeps walking" ,
80- ) ;
81+ "The quick brown fox leaps over the lazy dog and keeps walking" ) ;
8182 const resolved = resolveWithClassification (
8283 pending , { stillValid : true , reason : "meaning preserved" } ) ;
8384 expect ( resolved ) . toEqual ( {
84- status : "fresh" ,
85- tier : 2 ,
85+ status : StalenessStatus . Fresh ,
86+ tier : StalenessTier . AgenticClassification ,
8687 editRatio : pending . editRatio ,
8788 reason : "meaning preserved" ,
8889 } ) ;
@@ -91,11 +92,10 @@ test("resolveWithClassification marks stillValid as fresh at tier 2", () => {
9192test ( "resolveWithClassification marks !stillValid as stale at tier 2" , ( ) => {
9293 const pending = checkTextStaleness (
9394 "The quick brown fox jumps over the lazy dog and keeps running" ,
94- "The quick brown fox leaps over the lazy dog and keeps walking" ,
95- ) ;
95+ "The quick brown fox leaps over the lazy dog and keeps walking" ) ;
9696 const resolved = resolveWithClassification (
9797 pending , { stillValid : false , reason : "meaning changed" } ) ;
98- expect ( resolved . status ) . toBe ( "stale" ) ;
98+ expect ( resolved . status ) . toBe ( StalenessStatus . Stale ) ;
9999} ) ;
100100
101101test ( "resolveWithClassification throws when called on a non-pending result" , ( ) => {
@@ -105,13 +105,14 @@ test("resolveWithClassification throws when called on a non-pending result", ()
105105} ) ;
106106
107107test ( "checkSegmentCountStaleness: unchanged count is fresh" , ( ) => {
108- expect ( checkSegmentCountStaleness ( 5 , 5 ) ) . toEqual ( { status : "fresh" , tier : 0 } ) ;
108+ expect ( checkSegmentCountStaleness ( 5 , 5 ) )
109+ . toEqual ( { status : StalenessStatus . Fresh , tier : StalenessTier . Fingerprint } ) ;
109110} ) ;
110111
111112test ( "checkSegmentCountStaleness: changed count is a Tier 3 structural break" , ( ) => {
112113 const result = checkSegmentCountStaleness ( 5 , 6 ) ;
113- expect ( result . status ) . toBe ( "stale" ) ;
114- expect ( result . tier ) . toBe ( 3 ) ;
114+ expect ( result . status ) . toBe ( StalenessStatus . Stale ) ;
115+ expect ( result . tier ) . toBe ( StalenessTier . StructuralBreak ) ;
115116 expect ( result . reason ) . toContain ( "5" ) ;
116117 expect ( result . reason ) . toContain ( "6" ) ;
117118} ) ;
0 commit comments