Skip to content

Commit 7062c20

Browse files
itcmsgrclaude
andcommitted
installer: PR26.5 — seed stub binaries in test mock for CI
Auditor flagged: TestStageAll_AllUnitNftbanOwnedExecStartPathsStaged_PR26_5 fails on CI because the runner ships a clean source checkout with no prebuilt binaries. lab2 happened to have prebuilt binaries from prior builds, so the test passed there. The test's intent is correct (assert every shipped unit's nftban-owned ExecStart path is staged), but it needs the binary source files to exist for the staging step to succeed. Fix: per auditor option 1, add a `seedStubBuiltBinaries` helper that populates `bin/<name>` with a stub byte-string in the test mock before StageAll. Production payload.go is unchanged. Helper applied to all 3 PR26.5 tests for environment consistency: TestStageAll_AllUnitNftbanOwnedExecStartPathsStaged_PR26_5 (the failing one) TestStageAll_AllPanelConfDStaged_PR26_5 TestStageAll_PR26_5_NewShellCategoriesStaged Lab proof — confirmed reproducer: rm -rf /root/nftban-src/bin && go test -count=1 -v -run PR26_5 ./... → all 3 PR26.5 tests PASS (was: 1 FAIL pre-fix on empty bin/) go test ./... → 66 packages PASS, 0 FAIL Production code: unchanged. The fix is fixture-only — no payload.go edits, no validate/ edits, no buildEntries change. Hard exclusions still preserved: no takeover preservation, no CSF binary handling, no cPanel/Plesk adapters, no shell decommission, no parser rewrite, no restore changes, no firewall mutation, no destructive dns2 retry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4a1dd31 commit 7062c20

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

internal/installer/payload/payload_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,25 @@ func isNftbanOwnedPath(p string) bool {
689689
p == "/usr/sbin/nftban"
690690
}
691691

692+
// seedStubBuiltBinaries seeds stub source files for the four Go binaries
693+
// that StageAll expects under bin/<name>. CI runners produce a clean source
694+
// checkout without prebuilt binaries — preloadAllRepoFilesIntoMock therefore
695+
// cannot pre-load them. This helper closes that test-environment gap so the
696+
// integration tests don't depend on a prior `./build.sh` invocation.
697+
//
698+
// Production correctness is unaffected: payload.StageAll's binary entries
699+
// remain category=binaries, srcRel=bin/<name>. On real installs the build
700+
// step produces these files; in tests we pretend they exist (with arbitrary
701+
// content) so the subsequent staging copy-or-skip succeeds.
702+
func seedStubBuiltBinaries(t *testing.T, mock *executor.MockExecutor, repoRoot string) {
703+
t.Helper()
704+
for _, name := range []string{"nftban-core", "nftband", "nftban-validate", "nftban-installer"} {
705+
p := filepath.Join(repoRoot, "bin", name)
706+
mock.Files[p] = []byte("stub-binary")
707+
mock.Dirs[filepath.Dir(p)] = true
708+
}
709+
}
710+
692711
// PR26.5 R1: every nftban-owned ExecStart path declared by the shipped
693712
// install/systemd/*.service unit files MUST be staged by payload.StageAll.
694713
// dns2 evidence (2026-04-30) failed exactly this — exporter/cron/scripts/
@@ -698,6 +717,10 @@ func TestStageAll_AllUnitNftbanOwnedExecStartPathsStaged_PR26_5(t *testing.T) {
698717

699718
mock := executor.NewMockExecutor()
700719
preloadAllRepoFilesIntoMock(t, mock, repoRoot)
720+
// CI runners ship a clean checkout without prebuilt binaries; seed
721+
// stubs so the binary staging entries succeed and we can verify the
722+
// end-state-on-mock invariant the test was written to enforce.
723+
seedStubBuiltBinaries(t, mock, repoRoot)
701724

702725
if err := StageAll(mock, repoRoot, &detect.DistroInfo{ID: "rocky"}, newTestLogger()); err != nil {
703726
t.Fatalf("StageAll: %v", err)
@@ -748,6 +771,12 @@ func TestStageAll_AllPanelConfDStaged_PR26_5(t *testing.T) {
748771

749772
mock := executor.NewMockExecutor()
750773
preloadAllRepoFilesIntoMock(t, mock, repoRoot)
774+
// Seed stub binaries so StageAll's binary entries succeed on CI runners
775+
// that don't have prebuilt binaries in bin/. Doesn't affect this test's
776+
// assertions (they check /etc/nftban/conf.d/panels/* destinations, not
777+
// /usr/lib/nftban/bin/*) but keeps StageAll's overall completeness behavior
778+
// consistent across tests.
779+
seedStubBuiltBinaries(t, mock, repoRoot)
751780

752781
if err := StageAll(mock, repoRoot, &detect.DistroInfo{ID: "rocky"}, newTestLogger()); err != nil {
753782
t.Fatalf("StageAll: %v", err)
@@ -788,6 +817,8 @@ func TestStageAll_PR26_5_NewShellCategoriesStaged(t *testing.T) {
788817

789818
mock := executor.NewMockExecutor()
790819
preloadAllRepoFilesIntoMock(t, mock, repoRoot)
820+
// Stub binaries (CI-runner consistency). See helper doc.
821+
seedStubBuiltBinaries(t, mock, repoRoot)
791822

792823
if err := StageAll(mock, repoRoot, &detect.DistroInfo{ID: "rocky"}, newTestLogger()); err != nil {
793824
t.Fatalf("StageAll: %v", err)

0 commit comments

Comments
 (0)