Skip to content

fix(#730): prevent squad.agent.md silent deletion — 3 code path fixes#731

Closed
diberry wants to merge 1 commit intodevfrom
squad/730-agent-file-silent-deletion
Closed

fix(#730): prevent squad.agent.md silent deletion — 3 code path fixes#731
diberry wants to merge 1 commit intodevfrom
squad/730-agent-file-silent-deletion

Conversation

@diberry
Copy link
Copy Markdown
Collaborator

@diberry diberry commented Apr 1, 2026

Summary

Prevents squad.agent.md from silently disappearing after upgrade/init when the template source is missing or the file becomes empty. Fixes 3 code paths where the agent discovery file could vanish without warning, breaking Copilot's ability to find the Squad agent.

Closes #730

Root Causes Fixed

Code Path File Problem Fix
Version-current upgrade upgrade.ts:497-530 Silently skipped when template missing Added else clause with fallback generation + empty file detection
Init agent file creation init.ts:1031-1059 No else clause when template missing Added fallback generation when template unavailable
Doctor health check doctor.ts:382-412 Empty file reported as warn Upgraded severity to fail, updated message to mention Copilot discovery

Test Coverage

6 tests in test/cli/agent-file-resilience.test.ts:

Test Status What It Proves
upgrade warns/errors when template source missing ✅ PASS Version-current path no longer silently skips
init creates agent file even when template dir empty ✅ PASS Fallback generation works
upgrade restores empty squad.agent.md ✅ PASS Empty file auto-recovered
doctor reports fail (not warn) for empty file ✅ PASS Severity correctly elevated
baseline: version-current upgrade refreshes agent file ✅ PASS Happy path preserved
baseline: empty file restored via full-upgrade path ✅ PASS Happy path preserved

All 6 new tests pass. All 55 existing tests pass.

Files Changed

  • test/cli/agent-file-resilience.test.ts — new: 6 resilience tests
  • packages/squad-cli/src/cli/core/upgrade.ts — fix: fallback generation + empty file detection
  • packages/squad-sdk/src/config/init.ts — fix: fallback generation when template missing
  • packages/squad-cli/src/cli/commands/doctor.ts — fix: empty file severity warn→fail
  • test/cli/doctor.test.ts — updated: expect fail instead of warn
  • CHANGELOG.md — added entry under [Unreleased] ### Fixed

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Copilot AI review requested due to automatic review settings April 1, 2026 22:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Vitest suite that reproduces issue #730 by exercising init, upgrade, and doctor behaviors around .github/agents/squad.agent.md when the template source is missing or the agent file is empty/nearly-empty.

Changes:

  • Add new integration-style tests covering upgrade “already current” refresh behavior when squad.agent.md.template is missing.
  • Add SDK initSquad test to demonstrate missing-template behavior for agent file creation.
  • Add doctor check expectation for empty squad.agent.md severity.

Comment thread test/cli/agent-file-resilience.test.ts Outdated
Comment thread test/cli/agent-file-resilience.test.ts
Comment thread test/cli/agent-file-resilience.test.ts
Comment thread test/cli/agent-file-resilience.test.ts Outdated
Comment thread test/cli/agent-file-resilience.test.ts Outdated
diberry added a commit that referenced this pull request Apr 1, 2026
- Remove stale "EXPECTED: FAIL" comments (tests now pass)
- Add existsSync guard to hideTemplate() with clear error message
- Replace magic number assertions with structural content checks
- Fix misleading test name for empty-file upgrade path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry added the skip-changelog Skip changelog enforcement for this PR label Apr 1, 2026
@diberry diberry force-pushed the squad/730-agent-file-silent-deletion branch from 0f8a879 to fa4cbba Compare April 2, 2026 01:04
@diberry diberry removed the skip-changelog Skip changelog enforcement for this PR label Apr 2, 2026
@diberry diberry changed the title test(#730): failing tests for squad.agent.md silent deletion bugs fix(#730): failing tests for squad.agent.md silent deletion bugs Apr 2, 2026
@diberry diberry changed the title fix(#730): failing tests for squad.agent.md silent deletion bugs fix(#730): prevent squad.agent.md silent deletion — 3 code path fixes Apr 2, 2026
@diberry
Copy link
Copy Markdown
Collaborator Author

diberry commented Apr 2, 2026

👋 @bradygaster — This PR is ready for your review and merge when you're ready. Single squashed commit, changelog entry included, CI should be green.

@diberry diberry requested a review from bradygaster April 2, 2026 02:01
@diberry diberry force-pushed the squad/730-agent-file-silent-deletion branch from fa4cbba to e78d781 Compare April 2, 2026 12:35
@diberry diberry added the skip-changelog Skip changelog enforcement for this PR label Apr 2, 2026
@diberry diberry closed this Apr 2, 2026
@diberry diberry reopened this Apr 2, 2026
Closes #730

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/730-agent-file-silent-deletion branch from e78d781 to f0731d4 Compare April 2, 2026 17:11
@diberry diberry removed the skip-changelog Skip changelog enforcement for this PR label Apr 2, 2026
diberry added a commit that referenced this pull request Apr 2, 2026
The budget calculation changes in nap.ts were unrelated to config
versioning and conflict with PR #731. The correct version is already
in dev (merged via #746). Reverting to dev to eliminate merge conflict.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry
Copy link
Copy Markdown
Collaborator Author

diberry commented Apr 2, 2026

Closing in favor of #762 which addresses the same issue (#730) with a cleaner approach (optional warnings field, team-reviewed).

@diberry diberry closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: squad.agent.md silently disappears after upgrade when template source is missing

2 participants