@@ -32,6 +32,7 @@ import {
3232} from "../utils/checkPipeline.js" ;
3333import { resolveCompositionViewportFromHtml } from "../utils/compositionViewport.js" ;
3434import { consumeCommandResult } from "../utils/commandResult.js" ;
35+ import { ambiguousIssue } from "../utils/motionAudit.js" ;
3536import type { ProjectLintResult } from "../utils/lintProject.js" ;
3637import type {
3738 LayoutIssue ,
@@ -1110,6 +1111,171 @@ describe("check pipeline", () => {
11101111 expect ( browser ) . toHaveBeenCalledTimes ( 1 ) ;
11111112 } ) ;
11121113
1114+ it ( "still audits layout when the motion sidecar is invalid" , async ( ) => {
1115+ const motion : MotionSpecResolution = {
1116+ kind : "invalid" ,
1117+ path : "/project/index.motion.json" ,
1118+ message : 'assertions[0] (staysInFrame): "selector" must be a non-empty string' ,
1119+ } ;
1120+ const driver = fakeDriver ( {
1121+ collectLayout : vi . fn ( async ( time : number ) => [ layoutIssue ( "error" , { time } ) ] ) ,
1122+ } ) ;
1123+ const { report, browser } = await runScenario ( driver , { } , { motion } ) ;
1124+
1125+ expect ( browser ) . toHaveBeenCalledTimes ( 1 ) ;
1126+ expect ( report . layout . findings . length ) . toBeGreaterThan ( 0 ) ;
1127+ expect ( report . motion . findings ) . toEqual ( [
1128+ expect . objectContaining ( { code : "motion_spec_invalid" , severity : "error" } ) ,
1129+ ] ) ;
1130+ expect ( report . motion ) . toMatchObject ( {
1131+ enabled : true ,
1132+ specPath : "/project/index.motion.json" ,
1133+ samples : 0 ,
1134+ } ) ;
1135+ expect ( report . ok ) . toBe ( false ) ;
1136+ } ) ;
1137+
1138+ it ( "does not sample motion for an invalid sidecar" , async ( ) => {
1139+ const motion : MotionSpecResolution = {
1140+ kind : "invalid" ,
1141+ path : "/project/index.motion.json" ,
1142+ message : "version 2 is not supported" ,
1143+ } ;
1144+ const driver = fakeDriver ( ) ;
1145+ const { report } = await runScenario ( driver , { } , { motion } ) ;
1146+
1147+ expect ( report . motion . samples ) . toBe ( 0 ) ;
1148+ expect ( driver . collectMotionFrame ) . not . toHaveBeenCalled ( ) ;
1149+ } ) ;
1150+
1151+ it ( "keeps evaluating the unambiguous assertions when one selector is ambiguous" , async ( ) => {
1152+ const motion : MotionSpecResolution = {
1153+ kind : "valid" ,
1154+ path : "/project/index.motion.json" ,
1155+ spec : {
1156+ assertions : [
1157+ { kind : "appearsBy" , selector : ".item" , bySec : 1 } ,
1158+ { kind : "appearsBy" , selector : "#hero" , bySec : 0.2 } ,
1159+ ] ,
1160+ } ,
1161+ } ;
1162+ const driver = fakeDriver ( {
1163+ getDuration : vi . fn ( async ( ) => 1 ) ,
1164+ findAmbiguousSelectors : vi . fn ( async ( ) => [
1165+ { ...layoutIssue ( "error" , { code : "motion_selector_ambiguous" } ) , selector : ".item" } ,
1166+ ] ) ,
1167+ collectMotionFrame : vi . fn ( async ( time : number ) => heroMotionFrame ( time , ( t ) => t >= 0.5 ) ) ,
1168+ } ) ;
1169+ const { report } = await runScenario ( driver , { } , { motion } ) ;
1170+
1171+ expect ( report . motion . samples ) . toBeGreaterThan ( 0 ) ;
1172+ expect ( report . motion . findings . map ( ( finding ) => finding . code ) . sort ( ) ) . toEqual ( [
1173+ "motion_appears_late" ,
1174+ "motion_selector_ambiguous" ,
1175+ ] ) ;
1176+ expect ( report . ok ) . toBe ( false ) ;
1177+ expect (
1178+ report . motion . findings . find ( ( finding ) => finding . code === "motion_selector_ambiguous" )
1179+ ?. message ,
1180+ ) . toContain ( "1 assertion(s) naming it were not evaluated" ) ;
1181+ expect ( driver . collectMotionFrame ) . toHaveBeenCalledWith ( expect . any ( Number ) , [ "#hero" ] , [ ] ) ;
1182+ } ) ;
1183+
1184+ it ( "separates the ambiguity message from the skipped-assertion count" , async ( ) => {
1185+ const motion : MotionSpecResolution = {
1186+ kind : "valid" ,
1187+ path : "/project/index.motion.json" ,
1188+ spec : { assertions : [ { kind : "appearsBy" , selector : ".item" , bySec : 1 } ] } ,
1189+ } ;
1190+ const driver = fakeDriver ( {
1191+ getDuration : vi . fn ( async ( ) => 1 ) ,
1192+ findAmbiguousSelectors : vi . fn ( async ( ) => [
1193+ { ...layoutIssue ( "error" ) , ...ambiguousIssue ( ".item" ) } ,
1194+ ] ) ,
1195+ } ) ;
1196+ const { report } = await runScenario ( driver , { } , { motion } ) ;
1197+
1198+ const message = report . motion . findings . find (
1199+ ( finding ) => finding . code === "motion_selector_ambiguous" ,
1200+ ) ?. message ;
1201+ expect ( message ) . toContain ( "exactly one. 1 assertion(s)" ) ;
1202+ } ) ;
1203+
1204+ it ( "counts skipped assertions per ambiguous selector, not across all of them" , async ( ) => {
1205+ const motion : MotionSpecResolution = {
1206+ kind : "valid" ,
1207+ path : "/project/index.motion.json" ,
1208+ spec : {
1209+ assertions : [
1210+ { kind : "appearsBy" , selector : ".item" , bySec : 1 } ,
1211+ { kind : "appearsBy" , selector : ".card" , bySec : 1 } ,
1212+ { kind : "appearsBy" , selector : ".card" , bySec : 2 } ,
1213+ ] ,
1214+ } ,
1215+ } ;
1216+ const driver = fakeDriver ( {
1217+ getDuration : vi . fn ( async ( ) => 1 ) ,
1218+ findAmbiguousSelectors : vi . fn ( async ( ) => [
1219+ { ...layoutIssue ( "error" , { code : "motion_selector_ambiguous" } ) , selector : ".item" } ,
1220+ { ...layoutIssue ( "error" , { code : "motion_selector_ambiguous" } ) , selector : ".card" } ,
1221+ ] ) ,
1222+ } ) ;
1223+ const { report } = await runScenario ( driver , { } , { motion } ) ;
1224+
1225+ const messages = report . motion . findings
1226+ . filter ( ( finding ) => finding . code === "motion_selector_ambiguous" )
1227+ . map ( ( finding ) => finding . message ) ;
1228+ expect ( messages . filter ( ( m ) => m . includes ( "1 assertion(s) naming it" ) ) ) . toHaveLength ( 1 ) ;
1229+ expect ( messages . filter ( ( m ) => m . includes ( "2 assertion(s) naming it" ) ) ) . toHaveLength ( 1 ) ;
1230+ } ) ;
1231+
1232+ it ( "drops a before assertion when either side is ambiguous, keeping the rest" , async ( ) => {
1233+ const motion : MotionSpecResolution = {
1234+ kind : "valid" ,
1235+ path : "/project/index.motion.json" ,
1236+ spec : {
1237+ assertions : [
1238+ { kind : "before" , a : "#hero" , b : ".item" } ,
1239+ { kind : "appearsBy" , selector : "#hero" , bySec : 0.2 } ,
1240+ ] ,
1241+ } ,
1242+ } ;
1243+ const driver = fakeDriver ( {
1244+ getDuration : vi . fn ( async ( ) => 1 ) ,
1245+ findAmbiguousSelectors : vi . fn ( async ( ) => [
1246+ { ...layoutIssue ( "error" , { code : "motion_selector_ambiguous" } ) , selector : ".item" } ,
1247+ ] ) ,
1248+ collectMotionFrame : vi . fn ( async ( time : number ) => heroMotionFrame ( time , ( t ) => t >= 0.5 ) ) ,
1249+ } ) ;
1250+ const { report } = await runScenario ( driver , { } , { motion } ) ;
1251+
1252+ expect ( report . motion . findings . map ( ( finding ) => finding . code ) . sort ( ) ) . toEqual ( [
1253+ "motion_appears_late" ,
1254+ "motion_selector_ambiguous" ,
1255+ ] ) ;
1256+ expect ( driver . collectMotionFrame ) . toHaveBeenCalledWith ( expect . any ( Number ) , [ "#hero" ] , [ ] ) ;
1257+ } ) ;
1258+
1259+ it ( "does not sample when every assertion names an ambiguous selector" , async ( ) => {
1260+ const motion : MotionSpecResolution = {
1261+ kind : "valid" ,
1262+ path : "/project/index.motion.json" ,
1263+ spec : { assertions : [ { kind : "appearsBy" , selector : ".item" , bySec : 1 } ] } ,
1264+ } ;
1265+ const driver = fakeDriver ( {
1266+ getDuration : vi . fn ( async ( ) => 1 ) ,
1267+ findAmbiguousSelectors : vi . fn ( async ( ) => [
1268+ { ...layoutIssue ( "error" , { code : "motion_selector_ambiguous" } ) , selector : ".item" } ,
1269+ ] ) ,
1270+ } ) ;
1271+ const { report } = await runScenario ( driver , { } , { motion } ) ;
1272+
1273+ expect ( report . motion . samples ) . toBe ( 0 ) ;
1274+ expect ( report . motion . findings . map ( ( finding ) => finding . code ) ) . toEqual ( [
1275+ "motion_selector_ambiguous" ,
1276+ ] ) ;
1277+ } ) ;
1278+
11131279 it ( "reports a failing appearsBy sidecar as motion_appears_late" , async ( ) => {
11141280 const motion : MotionSpecResolution = {
11151281 kind : "valid" ,
0 commit comments