devbox/internal/hub/sharename_test.go
shoemoney 5bfccdb297 fix(M7): review fixes — pidfile O_EXCL, publish race, backoff reset 🐛
Code-review pass on M6.5+M7:
- pidfile: claim via O_CREATE|O_EXCL and arbitrate live-vs-stale, so two
  `devbox start` invocations can't both win the guard and run concurrently
- hub: serialize publish (publishMu) so a case-clash check + create is atomic;
  reject share names ending in '.' (Windows strips it → silent collision)
- daemon: reset SSE backoff only after a genuinely healthy stream (2m), not the
  30s ceiling, so a hub that recycles connections doesn't pin a 30s event lag
- document that restore/deploy's delete pass is ignore/guard-filtered on purpose
  (never delete a user's gitignored runtime files or local secrets)
- test: pidfile claim/refuse/stale-reclaim arbitration
2026-06-23 01:37:58 -05:00

39 lines
1.2 KiB
Go

package hub
import "testing"
func TestValidateShareName(t *testing.T) {
existing := []string{"projects", "Repos"}
cases := []struct {
name string
ok bool
}{
{"projects", true}, // exact match of an existing share is fine (idempotent publish)
{"my-app_2", true}, // letters, digits, dash, underscore
{"web.staging", true},
{"", false}, // empty
{" lead", false}, // whitespace
{"trail ", false},
{"a/b", false}, // path separator (sub-paths are mount-side, not in the name)
{"a\\b", false}, // backslash
{"..", false}, // traversal
{".hidden", false}, // leading dot
{"trail.", false}, // trailing dot (Windows strips it)
{"-flag", false}, // leading dash
{"sp ace", false}, // interior space
{"emoji🎉", false}, // non-ASCII
{"CON", false}, // reserved Windows device name
{"lpt3", false}, // reserved (case-insensitive)
{"repos", false}, // case-clashes with existing "Repos"
{"REPOS", false}, // case-clash
}
for _, c := range cases {
err := ValidateShareName(c.name, existing)
if c.ok && err != nil {
t.Errorf("ValidateShareName(%q) = %v, want ok", c.name, err)
}
if !c.ok && err == nil {
t.Errorf("ValidateShareName(%q) = ok, want error", c.name)
}
}
}