@@ -1453,6 +1453,127 @@ func TestStripArchSuffix(t *testing.T) {
14531453 }
14541454}
14551455
1456+ // TestDiffChangedFileFilterIncludesScriptSourceFiles verifies that when only a
1457+ // script file changes (no YAML changes), the changed-file filter still includes
1458+ // the parent software package in the diff output. Regression test for #11.
1459+ func TestDiffChangedFileFilterIncludesScriptSourceFiles (t * testing.T ) {
1460+ current := & api.FleetState {
1461+ Teams : []api.Team {
1462+ {
1463+ ID : 1 ,
1464+ Name : "Workstations" ,
1465+ Software : api.TeamSoftware {
1466+ Packages : []api.TeamSoftwarePackage {
1467+ {
1468+ ReferencedYAMLPath : "software/mac/printers-hq/printers-hq.yml" ,
1469+ URL : "https://example.com/printers-hq-1.0.pkg" ,
1470+ },
1471+ {
1472+ ReferencedYAMLPath : "software/mac/slack/slack.yml" ,
1473+ URL : "https://example.com/slack-old.dmg" ,
1474+ },
1475+ },
1476+ },
1477+ },
1478+ },
1479+ }
1480+
1481+ proposed := & parser.ParsedRepo {
1482+ Teams : []parser.ParsedTeam {
1483+ {
1484+ Name : "Workstations" ,
1485+ Software : parser.ParsedSoftware {
1486+ Packages : []parser.ParsedSoftwarePackage {
1487+ {
1488+ RefPath : "software/mac/printers-hq/printers-hq.yml" ,
1489+ URL : "https://example.com/printers-hq-2.0.pkg" ,
1490+ SourceFile : "/repo/software/mac/printers-hq/printers-hq.yml" ,
1491+ SourceFiles : []string {
1492+ "/repo/software/mac/printers-hq/printers-hq-install.sh" ,
1493+ "/repo/software/mac/printers-hq/printers-hq-uninstall.sh" ,
1494+ },
1495+ },
1496+ {
1497+ RefPath : "software/mac/slack/slack.yml" ,
1498+ URL : "https://example.com/slack-new.dmg" ,
1499+ SourceFile : "/repo/software/mac/slack/slack.yml" ,
1500+ },
1501+ },
1502+ },
1503+ },
1504+ },
1505+ }
1506+
1507+ // Only the install script changed, no YAML changes.
1508+ changedFiles := []string {
1509+ "software/mac/printers-hq/printers-hq-install.sh" ,
1510+ }
1511+
1512+ results := Diff (current , proposed , nil , changedFiles )
1513+ if len (results ) != 1 {
1514+ t .Fatalf ("expected 1 result, got %d" , len (results ))
1515+ }
1516+ r := results [0 ]
1517+
1518+ // printers-hq should appear (its install script is in changedFiles).
1519+ if len (r .Software .Modified ) != 1 {
1520+ t .Fatalf ("expected 1 modified package (printers-hq via script match), got %d modified, %d added, %d deleted" ,
1521+ len (r .Software .Modified ), len (r .Software .Added ), len (r .Software .Deleted ))
1522+ }
1523+ if ! strings .Contains (r .Software .Modified [0 ].Name , "printers-hq" ) {
1524+ t .Errorf ("expected printers-hq in modified, got %q" , r .Software .Modified [0 ].Name )
1525+ }
1526+
1527+ // slack should be filtered out (its YAML is not in changedFiles).
1528+ for _ , m := range r .Software .Modified {
1529+ if strings .Contains (m .Name , "slack" ) {
1530+ t .Errorf ("slack should be filtered out, but found in modified: %q" , m .Name )
1531+ }
1532+ }
1533+ }
1534+
1535+ // TestDiffChangedFileFilterYAMLStillWorks verifies that the changed-file filter
1536+ // continues to work for YAML-only changes (no regression from script tracking).
1537+ func TestDiffChangedFileFilterYAMLStillWorks (t * testing.T ) {
1538+ current := & api.FleetState {
1539+ Teams : []api.Team {
1540+ {
1541+ ID : 1 ,
1542+ Name : "T" ,
1543+ Software : api.TeamSoftware {
1544+ Packages : []api.TeamSoftwarePackage {
1545+ {ReferencedYAMLPath : "software/mac/app/app.yml" , URL : "https://example.com/old.pkg" },
1546+ },
1547+ },
1548+ },
1549+ },
1550+ }
1551+
1552+ proposed := & parser.ParsedRepo {
1553+ Teams : []parser.ParsedTeam {
1554+ {
1555+ Name : "T" ,
1556+ Software : parser.ParsedSoftware {
1557+ Packages : []parser.ParsedSoftwarePackage {
1558+ {
1559+ RefPath : "software/mac/app/app.yml" ,
1560+ URL : "https://example.com/new.pkg" ,
1561+ SourceFile : "/repo/software/mac/app/app.yml" ,
1562+ SourceFiles : []string {"/repo/software/mac/app/install.sh" },
1563+ },
1564+ },
1565+ },
1566+ },
1567+ },
1568+ }
1569+
1570+ results := Diff (current , proposed , nil , []string {"software/mac/app/app.yml" })
1571+ r := results [0 ]
1572+ if len (r .Software .Modified ) != 1 {
1573+ t .Fatalf ("expected 1 modified (YAML match), got %d" , len (r .Software .Modified ))
1574+ }
1575+ }
1576+
14561577// findTeam locates a DiffResult by team name, failing the test if not found.
14571578func findTeam (t * testing.T , results []DiffResult , name string ) * DiffResult {
14581579 t .Helper ()
0 commit comments