@@ -2,7 +2,10 @@ import type { GitOriginalityMeterResult } from "@forkara/contracts";
22import { renderToStaticMarkup } from "react-dom/server" ;
33import { describe , expect , it } from "vitest" ;
44
5- import { OriginalityMeterReport } from "./EnvironmentOriginalityMeterSection" ;
5+ import {
6+ isComputedOriginalityResult ,
7+ OriginalityMeterReport ,
8+ } from "./EnvironmentOriginalityMeterSection" ;
69
710function result ( overrides : Partial < GitOriginalityMeterResult > = { } ) : GitOriginalityMeterResult {
811 return {
@@ -71,3 +74,27 @@ describe("OriginalityMeterReport", () => {
7174 expect ( html ) . toContain ( "Upstream history may apply" ) ;
7275 } ) ;
7376} ) ;
77+
78+ describe ( "isComputedOriginalityResult" , ( ) => {
79+ it . each ( [ 0 , 25 , 100 ] ) ( "accepts a genuine computed %i%% result" , ( scorePercent ) => {
80+ expect ( isComputedOriginalityResult ( result ( { scorePercent } ) ) ) . toBe ( true ) ;
81+ } ) ;
82+
83+ it . each ( [ "missing_upstream" , "incomplete_history" , "unrelated_history" ] as const ) (
84+ "rejects the %s provenance state" ,
85+ ( state ) => {
86+ expect ( isComputedOriginalityResult ( result ( { state, scorePercent : null } ) ) ) . toBe ( false ) ;
87+ } ,
88+ ) ;
89+
90+ it ( "rejects loading and read-error paths that have no result" , ( ) => {
91+ expect ( isComputedOriginalityResult ( undefined ) ) . toBe ( false ) ;
92+ expect ( isComputedOriginalityResult ( null ) ) . toBe ( false ) ;
93+ } ) ;
94+
95+ it ( "fails closed for malformed ready scores" , ( ) => {
96+ expect ( isComputedOriginalityResult ( result ( { scorePercent : Number . NaN } ) ) ) . toBe ( false ) ;
97+ expect ( isComputedOriginalityResult ( result ( { scorePercent : - 1 } ) ) ) . toBe ( false ) ;
98+ expect ( isComputedOriginalityResult ( result ( { scorePercent : 101 } ) ) ) . toBe ( false ) ;
99+ } ) ;
100+ } ) ;
0 commit comments