Skip to content

Add bash test suite and CI job#11

Merged
brycelelbach merged 3 commits into
brycelelbach:mainfrom
robobryce:issue-5-tests
Apr 30, 2026
Merged

Add bash test suite and CI job#11
brycelelbach merged 3 commits into
brycelelbach:mainfrom
robobryce:issue-5-tests

Conversation

@robobryce

Copy link
Copy Markdown

Summary

Adds a small bash test harness under tests/ plus a GitHub Actions test job. All tests run without gh auth or any network access — matching the constraint in #5.

Included tests:

  • test-git-sync.sh — builds synthetic upstream + fork bare repos with a real git clone in between, runs git-sync, asserts local main and fork/main both end up at upstream/main.
  • test-git-sync-prune.sh — same fixture plus ff-ancestor, patch-equivalent (cherry-picked onto a different base), novel, and current branches. Asserts the first two are pruned and the rest are kept. Self-skips when git-sync doesn't implement --prune, so this stays green on main until that change lands.
  • test-arg-validation.sh — feeds each script the error-path inputs that are rejected before any gh call (bad slug, owner/name-style name, unknown flag, etc.) and checks both exit code and the expected stderr message.

tests/run-all is a simple runner. Each test sets up its own tmpdir and cleans up on exit.

CI changes:

  • New test job runs tests/run-all.
  • lint job now also shellcheck --source-path=SCRIPTDIR -x over tests/ so the source directives for tests/lib.sh resolve.

Fixes #5.

Test plan

  • tests/run-all passes locally — 3/3 tests pass (prune test self-skips on main, which is expected).
  • shellcheck --source-path=SCRIPTDIR -x clean on every script under plugins/ and tests/.
  • python3 -c "import yaml; yaml.safe_load(open('.github/workflows/ci.yml'))" succeeds.

Comment thread test.bash
done

echo "--- agentskills.io skills ---"
python3 .github/validate_skills.py

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It seems like validate_skills.py should be in tests/

Top-level ./test.bash dispatcher with --lint / --unit / --secrets /
--all, mirroring the layout in autonomous-agent-bootstrap so "works
locally" == "passes CI". The CI workflow rewrites into three jobs
(lint, unit, secret-scan) each delegating to one ./test.bash flag.

Test layout (tests/*.bats, bats-driven):

- arg-validation.bats — each skill script rejects bad input before any
  gh or network call; verified for all four scripts.
- git-sync.bats — fast-forward sync against synthetic upstream/fork
  bare repos built by make_contributor_fixture in tests/lib.bash. Also
  covers --prune against ff-ancestor / patch-equivalent / novel /
  current / synced branches.
- git-create.bats, git-fork.bats, git-clone.bats — full end-to-end
  coverage. A stub `gh` at tests/stubs/gh handles the handful of
  subcommands the scripts invoke (api user, repo create / fork / edit
  / view) against a local bare-repo root, and a global
  url.<root>/.insteadOf https://github.com/ rewrite makes real `git
  clone` / `git push` hit that root. Each test runs the real script
  with no auth or network, asserts final repo/remote state, and
  verifies gh was called with the expected arguments via a per-run
  STUB_GH_LOG.

Fixes brycelelbach#5.
…g validation

After PR#7 (--prune), brycelelbach#9 (auto-merge / update-branch defaults), and brycelelbach#10
(dependabot + CodeQL security endpoints) landed, the test suite was
silently under-covering the new code paths. Fix the gaps and audit for
the rest.

Stub:
- tests/stubs/gh now handles `gh api --silent --method <V> /path
  [-f k=v ...]` as a logged no-op. A new STUB_GH_API_FAIL env var makes
  the stub fail for any api path containing a given substring, letting
  tests exercise the `|| echo warning` branch in security-settings.

New test cases:
- git-create: asserts all three security endpoints are called with the
  expected paths; honours [security] overrides in ~/.agitentic;
  tolerates a failing endpoint without failing the run.
- git-fork: asserts all three security endpoints are called against the
  fork slug; short-circuit path asserts no security calls either.
- git-sync: already-synced no-op; refuses divergent commits without
  --force; --force resets and force-pushes to fork.
- arg-validation: git-create rejects no-args and empty <name>;
  git-fork and git-clone reject no-args.

Also extends the "default repo settings" assertions to cover the two
PR#9 keys (enable-auto-merge, allow-update-branch), and drops the
now-unnecessary --prune soft-skip since PR#7 is on main.

Suite is 39/39 green.
Walked each script top-to-bottom and added a test for every
remaining reachable branch.

arg-validation.bats (+6):
- git-fork: too-many-args, --help.
- git-clone: too-many-args, --help.
- git-sync: --help.

git-create.bats (+3):
- AGITENTIC_CONFIG env var redirects config lookup.
- git not on PATH → 'git is required' exit 1.
- gh not on PATH → 'gh (GitHub CLI) is required' exit 1.

git-fork.bats (+7):
- ssh:// URL form, http:// URL form, trailing-slash slug stripping.
- [repo] overrides apply to the fork.
- [security] overrides apply to the fork.
- security endpoint failure is non-fatal.
- git-missing / gh-missing guards.

git-clone.bats (+5):
- https URL form, ssh URL form.
- Empty [account] defaults to gh user.
- git-missing / gh-missing guards.

git-sync.bats (+8):
- git-missing guard.
- Not inside a git repo.
- Missing upstream / missing fork remote.
- Uncommitted changes rejection.
- Creates local branch when it didn't exist.
- Syncs main while checked out on a different branch (update-ref).
- --branch <name> syncs a non-default branch.

Supporting change to tests/lib.bash: setup_restricted_paths builds
two minimal PATH sandbox directories (coreutils only / coreutils +
git) so the `command -v git` / `command -v gh` guards can be tested
even on hosts where the real git/gh live on the default PATH.

Suite is now 68/68 green.
@brycelelbach brycelelbach merged commit 4ba7525 into brycelelbach:main Apr 30, 2026
3 checks passed
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.

Add tests and CI

2 participants