squad_state_list fails for root on adapter-backed backends: StateBackendStorageAdapter.toRelative() returns "." for squadDir

Aberta
#2,231 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
63/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
typescript
Domínio
backend, cli

Direção de pesquisa

Start in packages/squad-sdk/src/state-backend.ts and inspect StateBackendStorageAdapter.toRelative() alongside its list and directory methods. Then read packages/squad-sdk/src/tools/index.ts for normalizeStateToolDir() and the existing key validation. Add regression coverage for root listing while preserving traversal and file-operation rejection; done means the listed root entries are returned and the specified invalid paths still fail.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

wave:1-next wave1:P1

Summary

squad_state_list with dir omitted (or "", or ".squad") fails on any backend routed through StateBackendStorageAdapter (observed with stateBackend: "two-layer"):

Failed to list state: State key must not contain . or .. path segments

squad_state_list {dir: "decisions"} works.

Environment

  • squad CLI v1.0.1 (WinGet bradygaster.Squad), Windows
  • .squad/config.json → stateBackend: "two-layer"; squad_state_health → State backend storage: StateBackendStorageAdapter
  • Source references below are from main @ 89d6302576ce03b87fe0519235854c9e8638737f (bug still present)

Minimal repro

  1. Repo with stateBackend: "two-layer" (or orphan / git-notes).
  2. Run squad state-mcp, call squad_state_list {}.
  3. Observe the error above.

Unit-level repro:

const adapter = new StateBackendStorageAdapter(new OrphanBranchBackend(repo), squadDir);
adapter.listSync(squadDir); // throws: State key must not contain . or .. path segments

Root cause

  1. packages/squad-sdk/src/tools/index.ts normalizeStateToolDir() correctly maps an omitted dir to "", then calls this.storage.listSync(path.join(this.squadRoot, "")), i.e. listSync(squadRoot).
  2. packages/squad-sdk/src/state-backend.ts StateBackendStorageAdapter.toRelative() has:
    if (fileCmp === squadCmp) {
      return '.';
    }
    
  3. Every backend list() runs normalizeKey(relativeDir). normalizeKey explicitly allows "" as root ("Empty string after normalization means root — valid for list() operations"), but "." is non-empty, so validateStateKey('.') throws.

The adapter emits a root sentinel the backends do not accept.

Suggested fix (keeps traversal rejection)

Do not relax validateStateKey. Map squadDir to "" only for list-shaped reads:

  • list / listSync / isDirectory / isDirectorySync: when the path resolves to squadDir, pass "".
  • Keep "." (and therefore rejection) for file operations and especially deleteDir/deleteDirSync. Returning "" there would turn deleteDir(squadDir) into a wipe of all state, and read("") on git backends could resolve to a tree object.

For example, add private toRelativeDir(p) { const r = this.toRelative(p); return r === '.' ? '' : r; } and use it in the four list methods.

Regression tests

  • adapter.listSync(squadDir) returns root entries for the orphan, git-notes, and two-layer backends.
  • squad_state_list {} and {dir: ""} succeed.
  • {dir: ".."}, {dir: "a/../b"}, and {dir: "."} still fail with the . or .. error.
  • adapter.deleteDirSync(squadDir) and adapter.readSync(squadDir) still throw.

Downstream report: OlyForge3D/PrintFarmer#3372

Linguagem predominante
TypeScript
Estrelas
3.4k
Forks
516
Merge médio
1d 15h
PRs com merge (30d)
116

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/squad

Todas as issues de github/squad

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.