Skip to content
Source
Sign inSign up
pingdotgg/t3code

Server reports a tracked directory as available after a Git branch replaces it with a file #48085

OpenKiritoXDone(GitHub profile, opens in a new tab) opened this issue 0 comments

I registered an external manuals/ directory with t3 project add --track. After I switched the external repository to a branch that stores its manual in a single file at the same path, the running server continued to return state: "plain" from workspace.listFolders. Settings → Projects → Repositories uses that state for its Folder badge. The tracked directory no longer exists on this branch.

Reproduce

  1. In a temporary Git repository, create one branch with manuals/readme and a second branch with a regular file named manuals.
  2. Check out the directory branch. Run t3 project add <separate-project> --track <git-repo>/manuals against a fresh server data directory.
  3. Request workspace.listFolders for that project. Switch to the file branch, then repeat the same request against the same running server. Switch back to check recovery.

On ddc72ec5c9 (macOS 26.2, Node 26.13.1), the server returned:

directory -> plain
absent -> missing
regular file -> plain
directory restored -> plain

Expected missing for the regular file, just as on a branch where the directory is absent. The project should retain the configured path and report plain again once the directory returns.

Runnable reproduction using Node, Git and the real project CLI and WebSocket API

Save as git-repro.mjs. From a repository checkout with dependencies installed, run node /path/to/git-repro.mjs. It uses a new temporary data directory and a loopback server, prints the four RPC results, and closes its own server.

import { execFileSync, spawn } from 'node:child_process';
import { once } from 'node:events';
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { createServer } from 'node:net';
import { tmpdir } from 'node:os';
import { delimiter, dirname, join } from 'node:path';
import { setTimeout as delay } from 'node:timers/promises';

const fixture = mkdtempSync(join(tmpdir(), 't3-folder-state-'));
const state = join(fixture, 'state');
const project = join(fixture, 'project');
const dependency = join(fixture, 'dependency');
const library = join(dependency, 'manuals');
const cli = 'apps/server/src/bin.ts';
const env = { PATH: [dirname(process.execPath), '/usr/bin', '/bin'].join(delimiter), DO_NOT_TRACK: '1' };
const run = (...args) => execFileSync(process.execPath, [cli, ...args, '--base-dir', state], { env, encoding: 'utf8', timeout: 30000 });
let server, ws, stopped;
try {
  mkdirSync(project);
  mkdirSync(dependency);
  const git = (...args) => execFileSync('git', ['-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid', ...args], {
    cwd: dependency, env: {...env, GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null'}, stdio: 'pipe'
  });
  git('init', '-b', 'no-manuals');
  git('commit', '--allow-empty', '-m', 'No manuals yet');
  git('switch', '-c', 'manuals-directory');
  mkdirSync(library);
  writeFileSync(join(library, 'readme'), 'User manual');
  git('add', '.'); git('commit', '-m', 'Publish a manuals directory');
  git('switch', '-c', 'manuals-file');
  git('rm', '-r', 'manuals');
  writeFileSync(library, 'User manual');
  git('add', 'manuals'); git('commit', '-m', 'Publish a single manuals file');
  git('switch', 'manuals-directory');
  const id = /Added project (\S+)/.exec(run('project', 'add', project, '--track', library))?.[1];
  if (!id) throw Error('Project creation failed');
  const lease = createServer().listen(0,'127.0.0.1');
  await once(lease,'listening');
  const {port} = lease.address();
  await new Promise(resolve => lease.close(resolve));
  server = spawn(process.execPath, [cli, 'serve', '--host', '127.0.0.1', '--port', String(port), '--base-dir', state], {env, stdio:'ignore'});
  stopped = once(server,'exit');
  const runtime = join(state,'userdata','server-runtime.json');
  for (let attempt=0; !existsSync(runtime) && attempt<300 && server.exitCode === null; attempt++) await delay(100);
  const {origin} = JSON.parse(readFileSync(runtime,'utf8'));
  const credential = run('auth','session','issue','--scope','filesystem:read','--ttl','5m','--token-only').trim();
  const response = await fetch(origin+'/api/auth/websocket-ticket',{method:'POST',headers:{Authorization:'Bearer '+credential}});
  if (!response.ok) throw Error('Ticket request: '+response.status);
  const {ticket} = await response.json();
  const url = new URL('/ws',origin.replace('http:', 'ws:'));
  url.searchParams.set('orchestrationProtocol','2'); url.searchParams.set('wsTicket',ticket);
  ws = new WebSocket(url);
  await once(ws,'open',{signal:AbortSignal.timeout(10000)});
  let next = 0;
  async function stateFor(label) {
    const requestId = String(++next);
    ws.send(JSON.stringify({_tag:'Request', id:requestId, tag:'workspace.listFolders', payload:{projectId:id}, headers:[]}));
    for (;;) {
      const [event] = await once(ws,'message',{signal:AbortSignal.timeout(10000)});
      const reply = [JSON.parse(event.data)].flat().find(row => row._tag==='Exit' && row.requestId===requestId);
      if (!reply) continue;
      if (reply.exit._tag!=='Success') throw Error(JSON.stringify(reply.exit));
      const entry = reply.exit.value.folders.find(f => f.path === library);
      console.log(label+' -> '+entry?.state);
      return;
    }
  }
  await stateFor('directory');
  git('switch', 'no-manuals');
  await stateFor('absent');
  git('switch', 'manuals-file');
  await stateFor('regular file');
  git('switch', 'manuals-directory');
  await stateFor('directory restored');
} finally {
  ws?.close();
  if (server && server.exitCode===null && server.signalCode===null) server.kill('SIGTERM');
  if (stopped) await stopped;
  rmSync(fixture,{recursive:true,force:true});
}
  1. tanstack-source added labelsbug

Sign in to join this conversation.