Skip to content

Keep build output inside the worktree - #72

Merged
yansfil merged 1 commit into
mainfrom
fix/build-output-in-tree
Sep 16, 2026
Merged

yansfil merged 1 commit into
mainfrom
fix/build-output-in-tree

Conversation

@yansfil

@yansfil yansfil commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

브랜치 하나를 빌드하고 검증할 때 생기는 산출물을 전부 그 워크트리 안으로 옮기고, 검증 진입점을 두 스크립트로 줄입니다.

지금까지 cargo test와 swift test의 산출물은 /tmp/hide-verify-<uid>/<checkout hash>/에 쌓였습니다.
"검증 중인 트리를 더럽히지 않는다"가 이유였는데, target/과 macos/.build/는 이미 ignore되어 있고 harness는 tracked 파일만 채점하므로 그 이유는 사라진 지 오래였습니다.
남은 것은 비용이었습니다: 워크트리를 지워도 캐시는 남아 7.5 GB의 고아 디렉터리가 생겼고, #71은 앱이 bash scripts/build-scratch.sh를 포크해서 그 경로를 계산해 지우는 코드까지 들였습니다.

이 PR 이후 빌드 결과는 cargo가 target/, SwiftPM이 macos/.build/에 쓰고, git worktree remove 한 번이 청소의 전부입니다.

바뀐 것:

  • scripts/build-scratch.sh, rust-test.sh, swift-test.sh 삭제. verify-cargo.sh와 verify-swift.sh가 유일한 Rust/Swift 검증 진입점이고, 스크래치를 쓰던 check 스크립트 7개가 이 둘을 부릅니다.
  • verify-cargo.sh는 호출자의 CARGO_TARGET_DIR와 무관하게 항상 워크트리의 target/을 쓰고, lint 모드(cargo fmt --check + clippy -D warnings)가 생겼습니다. verify-swift.sh test --filter X로 스위트 하나를 돌릴 수 있습니다.
  • worktree_cleanup.rs에서 /tmp 캐시를 찾아 지우던 owned_scratch_root와 그 실패를 표현하던 Partial 결과, 셸의 "partial" 분기를 삭제했습니다. 캐시가 워크트리 안에 있으면 git worktree remove가 함께 지웁니다.
  • agents/config.json의 검증 슬롯을 겹치는 4개(test/build/typecheck/lint가 cargo build --release를 세 번 확인)에서 다른 일을 하는 3개(test, lint, build=verify-swift.sh test)로 바꿨습니다. Sasu verify가 clippy와 fmt를 처음으로 돌립니다.
  • OperationalPolicyTests의 loginShellPathIsTheChildToolPATH는 실제 /bin/zsh -l을 2초 제한으로 띄우고 성공을 요구했습니다. 기계가 바쁘면 타임아웃으로 떨어지는 테스트였습니다. 프로브 결과를 주입하는 두 케이스(로그인 PATH가 있으면 그것, 없으면 /usr/bin:/bin)로 바꿨고, 비밀값이 자식 환경에 전달되지 않는 것도 고정값으로 확인합니다.
  • docs/BUILD.md를 다시 썼고, AGENTS.md, CONTRIBUTING.md, DESIGN.md, docs/README.md, verification-fixtures.md, BROWSER_PANES.md, PERFORMANCE_TESTING.md에서 지운 스크립트와 /tmp 경로를 걷어냈습니다.

Related

Breaking change

  • 로컬 bash scripts/rust-test.sh, swift-test.sh 호출은 verify-cargo.sh test, verify-swift.sh test [--filter X]로 바꿔야 합니다.
  • 기존 /tmp/hide-verify-<uid>/는 코드가 지우지 않습니다. 한 번 손으로 지우면 다시 생기지 않습니다.
  • 워크트리마다 macos/.build/(약 0.7 GB)가 생깁니다. 이전에는 같은 크기가 /tmp에 있었으므로 총량은 같고, 워크트리 삭제로 함께 사라진다는 점만 다릅니다.

Review focus

  • 사람이 판단할 것: Sasu 검증 슬롯에 lint(clippy)를 넣어 verify 시간이 늘어나는 것(cold 기준 수십 초)이 CI와 로컬 검증을 같은 게이트로 맞추는 값어치가 있는지.
  • 위험한 파일: herdr-core/src/worktree_cleanup.rs. RemovalOutcome enum을 String으로 접었으므로, 제거 결과가 "removed" 또는 "refused" 둘뿐이라는 것을 confirm의 재시도 건너뛰기 조건(row.result == "removed")과 함께 봐주세요.
  • 리뷰어에게 묻는 것: check-hide-full.sh의 로그가 target/hide-full.log로 갑니다. 다른 위치가 낫다면 알려주세요.

Risk surface

  • Failure path: git worktree remove가 실패하면 이전과 같이 행이 refused로 표시되고 Git의 stderr가 메시지로 보입니다. 이전에 partial(폴더는 지웠으나 /tmp 캐시는 못 지움)이던 상태는 더 이상 생길 수 없습니다.

Evidence

  • 확인한 것:
    • python3 -m unittest discover -s scripts/tests: 28개 통과. test_verification_builds.py의 실제 Cargo+SwiftPM 패키지 테스트가 CARGO_TARGET_DIR=must-not-use를 준 상태에서도 target/과 macos/.build/만 쓰고, 코어 값이 바뀌면 Swift 실행파일이 따라 바뀌는 것을 확인.
    • bash scripts/verify-cargo.sh lint: fmt와 clippy 통과.
    • bash scripts/verify-cargo.sh test: 새 removal_deletes_the_selected_worktree_with_its_build_output_and_keeps_the_branch 포함 cleanup 테스트 5개 통과.
    • bash scripts/verify-swift.sh test: 444개 통과(cold, 릴리스 코어 빌드 포함 4분 44초). 실행 후 /tmp/hide-verify-<uid>/에 새 디렉터리가 생기지 않고 target/과 macos/.build/만 생긴 것을 확인.
    • 저장소 게이트: no-workstation-identity, harness-ignore-anchor, agent-asset-committed, capability-readers-off-lock, worktree-removal-boundary, design-contract, no-attribution 통과.
  • 확인하지 못한 것과 그 이유:
    • session_sync::tests::coordinator_recovers_event_gap_with_one_fresh_snapshot_and_stops_its_reader, coordinator_resumes_from_the_last_event_without_fetching_another_snapshot 두 개가 condition did not become true before deadline으로 실패합니다. 이 PR이 건드리지 않은 파일이고, 같은 기계의 main 체크아웃에서도 같은 두 개가 같은 이유로 실패하는 것을 확인했습니다(다른 워크트리 세 곳이 동시에 빌드 중이던 조건). 별도 이슈로 다룹니다.
    • Overview의 merged-worktree cleanup UI를 실제 앱에서 눌러보지는 않았습니다. 바뀐 것은 partial 색상 분기 제거 하나이고, 그 상태를 만들 코드 경로가 없어졌습니다.

AI tooling

  • 사람이 직접 작성 - [ ] 일부를 AI 도구로 작성 - [x] 대부분을 AI 도구로 작성

손으로 확인한 것: /tmp/hide-verify-501/ 아래 4개 디렉터리 중 하나(1.7 GB)가 존재하지 않는 워크트리의 것임을 해시를 각 체크아웃 경로에서 다시 계산해 대조했고, macos/ 루트의 .o/.d/.swiftdeps 60개가 2026-08-31 하루에 생긴 swiftc 직접 실행 잔재임을 mtime으로 확인했습니다.

Cargo and SwiftPM now write to their default locations, target/ and
macos/.build/, both ignored, so git worktree remove is the whole cleanup.
The /tmp scratch layout keyed by checkout hash is removed with the script
that computed it, the two duplicate test wrappers, and the cleanup step
that forked bash from the app to find and delete that cache.

verify-cargo.sh and verify-swift.sh are the only Rust and Swift entrypoints;
the check scripts call them, verify-cargo.sh gains a lint mode, and the
harness slots become test, lint and build instead of three overlapping
release-build confirmations.

The login-shell PATH test injected the probe result instead of running a
real zsh under a two-second bound, which failed whenever the machine was
busy building.
@yansfil
yansfil merged commit 39f0048 into main Sep 16, 2026
5 checks passed
@yansfil
yansfil deleted the fix/build-output-in-tree branch September 16, 2026 10:08
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