Skip to content

mac: the opened file keeps its real name as the entry document - #655

Merged
GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/entry-document-name
Sep 15, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/entry-document-name

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Fixes the owner's most concrete multi-file complaint: "when opening a file not named main.tex, it still reads as main.tex." First PR of the multi-file root-document stack (a); (b)–(e) follow separately.

The bug

ShellModel.replaceProject(entryText:) hardcoded the entry document as main.tex (ShellModel.swift:769-771). All three entry points renamed the opened file:

  • File > Open — adoptOpenedText (DocumentFiles.swift:537)
  • FLASHTEX_SEED_FILE startup seed (ShellModel.swift:619)
  • Edit > Restore Discarded Buffer (DocumentFiles.swift:555)

So opening paper.tex produced a project whose entry document, activePath, every tab/diagnostic/caret path, and the compile request's entry_path all said main.tex. On the preview-controller route it was worse: attachController only roots the helper at the real directory when documentURL.lastPathComponent == entry.path, which the renaming made impossible for any other filename — the helper then ran in a session temporary project, losing the real project root (and with it any chance of sibling \input resolution on that route).

The fix

replaceProject(entryText:named:) takes the file's actual name; the three callers pass it (url.lastPathComponent, seed filename, kept.url?.lastPathComponent). The "main.tex" default remains for unsaved buffers with no file behind them. No protocol change — entry_path was always dynamic; the producer already resolves includes against the documents array.

Free consequence: with the name intact, controllerRoutesFiles (DocumentFiles.swift:729-732) now accepts non-main.tex entries, so helper-routed save/reload/file-status work for every filename instead of only main.tex.

Test edits (each justified)

  • DocumentFilesTests — new regression test testOpenedFileKeepsItsRealNameAsTheEntryDocument: opens paper.tex, asserts activePath / documents / project.entryPath all carry the real name; a restored discarded buffer keeps its name too.
  • DirtySnapshotsTests (direct route) — activePath after opening paper.tex is now paper.tex; the old assertion codified the bug.
  • DirtySnapshotsControllerTests — the scenario it pinned ("a file not named main.tex is a session project for the helper") is extinct: that mis-rooting was a symptom of this bug. The test now pins the rooted-ledger route: durable keys under the real name, reviewed reload viaController, discarded text kept in undo history + recoverableBuffer rather than the snapshot store (applyDiskState and the reload paths only write snapshots when !controllerRoutesFiles), and the save still writes the real file.
  • ControllerPipelineReviewTests — Finding 2's safety property (a save must reach the file the user opened, never a session copy) is preserved and now asserted through the rooted helper: controllerRoutesFiles flips to true, durable keys use the real name, and the on-disk file receives the edited text.

Doc comment in DirtySnapshots.swift updated to stop describing the extinct session-copy case.

Verification

Swift/AppKit does not build on this Linux box; CI's macos-26 lane (swift build + serial swift test with the real helpers built and exported) is the verification gate for this PR. No Rust code is touched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

Opening a file not named main.tex still read as main.tex: `replaceProject`
hardcoded the entry document's path, so File > Open (adoptOpenedText), the
FLASHTEX_SEED_FILE seed, and Restore Discarded Buffer all renamed the entry
to "main.tex". Every tab, diagnostic, caret path and the compile request's
entry_path then carried the wrong name — and `attachController` fell into
the session-temporary-project branch (documentURL.lastPathComponent never
matched the renamed entry), losing the real project root on the helper
route.

`replaceProject(entryText:named:)` now takes the file's actual name (the
default "main.tex" remains for unsaved buffers), and the three callers pass
it through. With the name intact the preview controller roots at the file's
own directory, so `controllerRoutesFiles` accepts non-main.tex entries and
saves/reloads/status route through the helper's rooted ledger.

Test updates, each because it codified the renaming:
- DocumentFilesTests: new regression test — open paper.tex, assert the
  entry document, activePath and project.entryPath all say paper.tex, and a
  restored discarded buffer keeps its name.
- DirtySnapshotsTests (direct route): activePath after opening paper.tex is
  now paper.tex.
- DirtySnapshotsControllerTests: the "file not named main.tex is a session
  project" scenario is extinct; the test now pins the rooted-ledger route —
  durable keys under the real name, reviewed reload via the helper
  (viaController), discarded text in undo history/recoverableBuffer rather
  than the snapshot store (applyDiskState and adoptOpenedText only write
  snapshots off the ledger route), save writes the real file.
- ControllerPipelineReviewTests: Finding 2's save-safety property (the save
  reaches the file the user opened) now holds through the rooted helper;
  controllerRoutesFiles flips to true and durable keys use the real name.

Implementation-Agent: claude-fable-5 (multi-file project lane)
Commit-Executor: claude-fable-5 (direct)
Co-authored-by: GoKubar <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant