gitgram/aitimemachine/beads/cmd/bd/nocow_linux_test.go
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

70 lines
2.0 KiB
Go

//go:build linux
package main
import (
"testing"
)
// TestApplyNoCOW_Linux verifies that applyNoCOW sets FS_NOCOW_FL on a
// directory when the underlying filesystem is btrfs. On non-btrfs
// temp-dirs the call must succeed as a silent no-op, because the ioctl
// is unsupported there. We skip the flag-set assertion unless we're
// actually on btrfs.
func TestApplyNoCOW_Linux(t *testing.T) {
dir := t.TempDir()
// applyNoCOW must not error on any filesystem (btrfs sets the flag,
// ext4/tmpfs/etc. are no-ops).
if err := applyNoCOW(dir); err != nil {
t.Fatalf("applyNoCOW returned unexpected error: %v", err)
}
onBtrfs, err := isBtrfs(dir)
if err != nil {
t.Fatalf("isBtrfs: %v", err)
}
if !onBtrfs {
t.Skipf("temp dir %s is not on btrfs; skipping flag-set assertion", dir)
}
set, err := hasNoCOW(dir)
if err != nil {
t.Fatalf("hasNoCOW: %v", err)
}
if !set {
t.Errorf("expected FS_NOCOW_FL to be set on %s after applyNoCOW", dir)
}
}
// TestApplyNoCOW_Idempotent verifies that calling applyNoCOW twice is
// safe and does not error on the second invocation. This matters because
// `bd doctor --fix` may re-apply the flag.
func TestApplyNoCOW_Idempotent(t *testing.T) {
dir := t.TempDir()
if err := applyNoCOW(dir); err != nil {
t.Fatalf("first applyNoCOW: %v", err)
}
if err := applyNoCOW(dir); err != nil {
t.Fatalf("second applyNoCOW: %v", err)
}
}
// TestHasNoCOW_UnsetOnFreshTempDir sanity-checks that a fresh temp dir
// does NOT have FS_NOCOW_FL set until we apply it. If the temp dir lives
// on a non-btrfs filesystem, hasNoCOW returns (false, nil) via the
// unsupported-error shim, which also satisfies this test.
func TestHasNoCOW_UnsetOnFreshTempDir(t *testing.T) {
dir := t.TempDir()
set, err := hasNoCOW(dir)
if err != nil {
t.Fatalf("hasNoCOW: %v", err)
}
if set {
// It's technically possible for a temp dir to inherit the flag
// from a parent directory that already had it set — skip in that
// case rather than fail.
t.Skipf("temp dir %s already has FS_NOCOW_FL inherited from parent", dir)
}
}