Repository navigation
test(lsp): open test documents under the test's own temp directory - #1513
Conversation
A document opened under no workspace folder has its own directory indexed, so the tests that opened documents at /tmp/<name> had the server scan the system temp directory and whatever model tree happened to sit there, and documents named relatively were placed in the package directory. Every helper and test now opens its document in a directory of its own from t.TempDir(); two tests pin that only the document's directory is indexed and that the helpers stay under the test root. Co-Authored-By: jason.han <hanhuijun@gmail.com>
debug_test.go is allowlisted at its size in tests/hygiene; the test that debugs a behavior exposed from another document moves to debug_cross_document_test.go and the allowlist records the smaller file. Co-Authored-By: jason.han <hanhuijun@gmail.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: jason.han <hanhuijun@gmail.com>
|
fd2159b shortens the doc comments on |
…wn directory Co-Authored-By: jason.han <hanhuijun@gmail.com>
|
4d8fdcf routes the five documents |
What and why
A document opened under no workspace folder has its own directory indexed, so its sibling imports resolve (
docs/guide/08-editors.md, "What the server indexes"). Severalinternal/frontend/lsptests opened their document at/tmp/<name>throughtextDocument/didOpen, so the server scanned the system temp directory and indexed whatever model tree happened to sit there (DidOpen→indexOpenedDirectory→projectOrDir=filepath.Dir→scanFolder(/tmp, 2000 directories)). Others opened documents named relatively (e2e.sysml,kit.sysml,fleet.sysml), whichuri.Fileresolved into the package directory, or under directories that do not exist (/w/,/ws/). None of those tests setrootUriorworkspaceFolders; the server's root discovery (project.EnclosingProjects) never walked up to/tmp— it adopted the file's own directory, as documented. The tests, not the server, pointed it at a shared directory.With a copy of eight
examples/trees under/tmp(2,920.sysml/.kermlfiles in 985 directories) ondevelopat 111a59a,go test -count=1 -v ./internal/frontend/lsp/...went fromok 12.3s(497 passing) toFAIL 343.9s: seven wire tests timed out at their 30 s pipe deadline while the server walked/tmp(TestWireDidChangeOmittedRangeReplacesDocument,…ZeroRangeInsertsAtStart,…NullRangeReplacesDocument,…MixedBatchAppliesInOrder,…RepublishesDiagnosticsOnBothPaths,TestRunServesSignatureHelpCodeLensAndInlayHints,TestRunServesEveryRequestOverOneStream), and ten more passed late (TestRunServesLibraryDocumentsOverStream0.00 s → 32.6 s,TestWireRangeFormattingAnswersEditsOnSelectedLines→ 29.8 s,TestRunServesSemanticTokensAndCodeAction→ 7.0 s, the sixsync_test.goTestDidOpen*/TestDidChange*tests → 3.3–4.0 s each).What changed, all under
internal/frontend/lsp:tempdoc_test.go:tempDocURI(t, name)places a document in a directory fromt.TempDir();testDocURI(t, name)keeps an absolute name as given (the collapsed-ports fixture pins/collapsed-ports.sysmlso its origins do not depend on the checkout, and a path at the filesystem root is never indexed) and places a bare one the same way.requireTestOwnedDirfails a test about to open a document in the working directory (where a bare name lands) or inos.TempDir();openDocandtestDocURIcall it, so every document opened through a helper is in a directory the test owns.newWireSessionopenswire.sysmlin its own directory (wireSession.urireplaces thefile:///tmp/wire.sysmlconstant);sync_test.go,run_test.go,protocol_features_test.go,protocol_editor_facts_test.go,stdlib_test.go(the stream test),integration_test.go,modeledit_test.go,modeledit_cross_document_test.go,render_filter_test.goand therenderServer/debugServerhelpers open their documents through the helpers.debug_test.gocall sites drop the/w/prefix; the duplicate-declaration test opens both documents in one directory and asserts on the paths it opened.opened_directory_test.go:TestOpenedDocumentIndexesOnlyItsOwnDirectoryopens a document in a subdirectory next to a model file in the parent and checks the sibling is indexed, the parent's file is not, andopenDirsholds only the document's directory.TestOpenHelpersStayUnderTheTestRootwrites a stray model file intoos.TempDir(), drives every helper (wireSession.open,openDoc,renderServer,debugServer,DidOpen) and fails if the stray file is indexed or any indexed directory lies outside the test's root. With the helpers pointed back atos.TempDir()this test fails (no publishDiagnostics for file:///tmp/wire.sysml within 30s).modeledit_cross_document_test.go: the five documents it opened under bare names (parts.sysml,views.sysml,motor.sysml) go throughtempDocURI.uri.Fileresolves a bare name withfilepath.Abs, so those opens indexed the package directoryinternal/frontend/lsp(go testruns a package's tests in that directory): zero model files and no subdirectories, so nothing from outside the test was indexed and the scan cost one directory listing, but which directory depends on the working directory, so they are now rooted the same way as every other open. The remaining bare names are never opened:depot.sysmlis set on disk throughws.SetOnDisk,missing.sysml,gone.sysmlandelsewhere.sysmlare requests about documents the server does not hold, andlifecycle_test.go'sfile:///tmp/dropped.sysmlgoes throughlifecycleHandlerwrapping a stub, soDidOpennever runs. Pointing one open back at a bare name, orrenderServerat/tmp/collapsed-ports.sysml, fails atrequireTestOwnedDir(opens in shared directory …; use tempDocURI).debug_test.gotodebug_cross_document_test.go, andtests/hygiene/size_test.gorecordsdebug_test.goat its smaller size (2127 lines).No assertion changed. Test-only change: no changelog fragment.
Sibling suites checked with the same tree under
/tmp:internal/frontend/repl,internal/frontend/grpc,tests/grpcandcmd/sysml-lspall pass with and without it (50.5 s vs 31.8 s wall for the four together, CPU contention from the parallel packages; no per-test movement). None of them scans a directory from a request path;cmd/sysml-lspopensfile:///m.sysml, at the filesystem root, whichindexOpenedDirectorynever indexes, and its/tmp/after-shutdown.sysmlis a hover after shutdown, never opened.How it was verified
go test -count=1 ./internal/frontend/lsp/...on this branch, 499 tests:/tmpcontentsok 12.3s(real 33 s with compile)ok 12.9s(real 13.6 s), 499 passingFAIL 343.9s, 7 failuresok 12.7s(real 13.4 s), 499 passing, slowest testTestDebugActionFailure5.2 s as withoutGates:
Dry merges of this head: clean with
origin/develop(111a59a) and with #1506 (fix/cache-key-build-identity, e956947).Checklist
go test ./...andmake lintpass locally (make test, the race suite, is the full CI tier)changes/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.md(test-only change, none needed)make docs-countsrun if a gate count moved (none moved)F4,K5) in the body, docs, or changelog