zzet--gortex
a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
68 行
2.2 KiB
Go
68 行
2.2 KiB
Go
package indexer
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
)
|
|
|
|
func TestIsTrackedStale(t *testing.T) {
|
|
dir := t.TempDir()
|
|
writeFile(t, filepath.Join(dir, "a.go"), "package a\n\nfunc A() {}\n")
|
|
|
|
g := graph.New()
|
|
idx := newTestIndexer(g)
|
|
idx.SetRootPath(dir)
|
|
_, err := idx.Index(dir)
|
|
require.NoError(t, err)
|
|
|
|
// Freshly indexed: not stale. Unknown / untracked paths are never
|
|
// tracked-stale (the key difference from IsStale, which treats an
|
|
// unknown file as stale).
|
|
require.False(t, idx.IsTrackedStale("a.go"))
|
|
require.False(t, idx.IsTrackedStale("does_not_exist.go"))
|
|
require.False(t, idx.IsTrackedStale("untracked.md"))
|
|
|
|
// Touch the file with a later mtime: now tracked-stale.
|
|
future := time.Now().Add(2 * time.Second)
|
|
require.NoError(t, os.Chtimes(filepath.Join(dir, "a.go"), future, future))
|
|
require.True(t, idx.IsTrackedStale("a.go"))
|
|
}
|
|
|
|
// TestTrackedFileStateMissingFile proves the three-way verdict that splits a
|
|
// deleted-on-disk file out of the binary stale check: fresh -> stale (mtime
|
|
// drift) -> missing (the file is gone). IsTrackedStale folds missing into
|
|
// not-stale, so only TrackedFileState surfaces the deletion.
|
|
func TestTrackedFileStateMissingFile(t *testing.T) {
|
|
dir := t.TempDir()
|
|
target := filepath.Join(dir, "a.go")
|
|
writeFile(t, target, "package a\n\nfunc A() {}\n")
|
|
|
|
g := graph.New()
|
|
idx := newTestIndexer(g)
|
|
idx.SetRootPath(dir)
|
|
_, err := idx.Index(dir)
|
|
require.NoError(t, err)
|
|
|
|
// Freshly indexed and untracked paths both read fresh.
|
|
require.Equal(t, FileFresh, idx.TrackedFileState("a.go"))
|
|
require.Equal(t, FileFresh, idx.TrackedFileState("untracked.md"))
|
|
|
|
// mtime drift -> stale.
|
|
future := time.Now().Add(2 * time.Second)
|
|
require.NoError(t, os.Chtimes(target, future, future))
|
|
require.Equal(t, FileStale, idx.TrackedFileState("a.go"))
|
|
|
|
// Deleted on disk -> missing, and IsTrackedStale must NOT report it as
|
|
// stale (the distinction the freshness rider relies on).
|
|
require.NoError(t, os.Remove(target))
|
|
require.Equal(t, FileMissing, idx.TrackedFileState("a.go"))
|
|
require.False(t, idx.IsTrackedStale("a.go"),
|
|
"a deleted file is missing, not stale — IsTrackedStale folds it into not-stale")
|
|
}
|