Skip to content

test(claude): cover claudesession env, staging, state script and worktrees - #1275

Merged
cdalar merged 1 commit into
mainfrom
test-claudesession
Oct 27, 2026
Merged

cdalar merged 1 commit into
mainfrom
test-claudesession

Conversation

@cdalar

@cdalar cdalar commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Adds 9 tests to cmd/claudesession_test.go. Coverage of claudesession.go goes from 84.8% to 97.0%.

What they guard

  • Token mode fails instead of falling back: with token auth and no saved token, the command fails and points to onctl claude login. Auto mode falls back to /login on the box. A fake security keeps the test away from the real Keychain.
  • API keys reach Claude exactly: the env file is sourced by sh, and a key containing ', $ and backticks arrives unchanged, with surrounding whitespace trimmed. The approval suffix is the key's last 20 characters.
  • Secrets stay out of ssh's arguments: stageClaudeEnv writes them to a 0600 file. They never appear in ssh's arguments, and an empty env makes no ssh call.
  • The state script keeps the box's settings: it leaves the box's theme and approved keys alone and doesn't add the same key twice. It handles a missing ~/.claude.json and a directory name full of shell metacharacters. This test skips when jq isn't installed.
  • The task-name pattern holds: it is the only check on the task name, which goes into the worktree script unquoted.
  • Worktrees: a directory that isn't a git repo is refused and leaves nothing behind, and a project path containing a space works.

I deliberately broke claudesession.go 13 ways, one at a time, and each break made at least one new test fail.

Known gaps (not addressed here)

  • An existing check at claudesession_test.go:66-69 only logs with t.Logf, so it can never fail.
  • Without jq installed, the state-script tests skip.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ba6Vc66D5hH1xSTvJcCbVz

…trees

Adds tests that guard why each behavior matters: token mode fails loudly
instead of falling back to /login, API keys survive sh sourcing exactly,
secrets reach the box via a 0600 file and never ssh argv, the state
script keeps box-side theme/keys and dedupes approvals, task names stay
within the pattern that protects the unquoted worktree path, and
worktrees need git and handle paths with spaces.

claudesession.go coverage: 84.8% -> 97.0%.

Claude-Session: https://claude.ai/code/session_01Ba6Vc66D5hH1xSTvJcCbVz
@cdalar
cdalar merged commit 5b1c68f into main Oct 27, 2026
12 checks passed
@cdalar
cdalar deleted the test-claudesession branch October 27, 2026 17:37
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.64%. Comparing base (d9e8c9c) to head (01a2420).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1275      +/-   ##
==========================================
+ Coverage   50.44%   50.64%   +0.19%     
==========================================
  Files          83       83              
  Lines        9822     9822              
==========================================
+ Hits         4955     4974      +19     
+ Misses       4867     4848      -19     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant

⌂ 换网址