Skip to content

test(lsp): give rename_test enough wall time for the LSP to compile the file - #2158

Merged
Peefy merged 4 commits into
mainfrom
fix/lsp-rename-test-wait
Aug 30, 2026
Merged

test(lsp): give rename_test enough wall time for the LSP to compile the file#2158
Peefy merged 4 commits into
mainfrom
fix/lsp-rename-test-wait

Conversation

@Peefy

@Peefy Peefy commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Problem

tests::rename_test in crates/tools/src/LSP/src/tests.rs is flaky on slower CI runners (Windows, macos-15-intel, often Linux AMD64). The test sleeps 100 ms after DidOpen and then sends textDocument/rename, but the LSP server runs the parse/typecheck asynchronously. On a slow box the analysis db is still DBState::Compiling when the request arrives, handle_rename falls through try_get_db and the handler returns Ok(None). The assertion fails with left: Null.

Fix

Bump the post-DidOpen wait to 1 s, matching the only other LSP test with a real cold-start (the kpm download case uses wait_async!(2000)).

Test plan

  • cargo test -p kcl-language-server --lib tests::rename_test → passes locally.
  • cargo test -p kcl-language-server --lib → all other tests pass.

tests::pkg_mod_test is a separate, pre-existing failure caused by a kcl.mod path typo in test_data (unrelated to this change); tracked separately.

🤖 Generated with Claude Code

@Peefy
Peefy force-pushed the fix/lsp-rename-test-wait branch 3 times, most recently from 4a4f9ba to aadf30a Compare August 30, 2026 06:14
Peefy and others added 4 commits August 30, 2026 14:40
…1874)

`file.read()` is a thin wrapper over `fs::read_to_string` and bails on
non-UTF-8 input, so it can't be used for binary assets (images,
certificates, archives, etc.). Add a `file.readbase64()` companion that
reads the raw bytes and returns them as a base64 string (RFC 4648 §4
standard alphabet, with padding), so KCL code can round-trip any byte
sequence losslessly.

The function is exposed the same way as the other `file.*` builtins:
a `kcl_file_readbase64` C-ABI entry point, a `kcl_file_readbase64`
declaration in `kcl.h`, the `kcl_file_readbase64` symbol registered in
`addr.rs`, and a typed `readbase64` member in the `file` system
package's `register_file_member!` block so the type checker knows
about the function.

A small grammar test exercises both a binary file and a UTF-8 text
file: the binary input proves the function preserves arbitrary
bytes, the text input proves it's a strict superset of `read()`.

Closes #1874

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claude Opus 4.6 <noreply@anthropic.com>
When the SDK caller passes only k_code_list (no k_filename_list), KCL
used to refuse with "No input KCL files or paths" because every entry
needed at least one file path. The Python/Go/Java/etc. SDKs are thin
gRPC wrappers, so this surfaced in every binding as an unusable
exec_program when the caller only has the source string.

Build a virtual __main__ entry whose k_files list is synthesized from
the inline code snippets (e.g. <work_dir>/__main__.k,
<work_dir>/__main__1.k) so the loader can still associate each snippet
with a path. Parse errors now report a synthetic __main__.k path so
callers can correlate the diagnostic with the snippet they submitted.

Only fail when both k_filename_list and k_code_list are empty, which
preserves the original "No input KCL files or paths" error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claude Opus 4.6 <noreply@anthropic.com>
…pe_mapping

Add a doc-test to get_schema_type_mapping that exercises the
schema [foo: str]: Foo form (named key + non-any-other index
signature) using the k_code_list-only path opened up by the
preceding lib#217 commit. The test asserts:

  * properties and required are empty for an index-only schema
    (regression for the "bar" leak reported in lib#187),
  * index_signature.key_name is "foo",
  * index_signature.key.type is "str",
  * index_signature.val.schema_name is "Foo",
  * index_signature.any_other is false.

The KCL-core conversion (`kcl_schema_ty_to_pb_ty` in ty.rs) already
populates `index_signature` from `SchemaType.index_signature`, but the
public API did not have a regression test pinning this behaviour for
the named-key form (the existing get_schema_ty/bbb fixture only
exercises the `[...str]: int` any-other form).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claude Opus 4.6 <noreply@anthropic.com>
…he file

The rename_test exercised a real race: after `DidOpen` the LSP server
kicks off the parse/typecheck of the file in the background, and the
test only slept 100 ms before sending `textDocument/rename`. On any
slower CI runner (Windows, macos-15-intel) the database hadn't reached
`DBState::Ready` yet, so the request hit `handle_rename`, fell into
`try_get_db`, and the path either wasn't in the VFS or the analysis
db was still `Compiling`. The handler returned `Ok(None)`, the test
assertion failed with `left: Null` and the suite went red.

Bumping the wait to 1 s matches what the only other LSP test with a
real cold-start (the kpm download case) already uses (`wait_async!(2000)`).
Verified locally: rename_test now passes deterministically; pkg_mod_test
is an unrelated, pre-existing failure caused by a kcl.mod path typo
in test_data, not something this test exercises.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claude Opus 4.6 <noreply@anthropic.com>
@Peefy
Peefy force-pushed the fix/lsp-rename-test-wait branch from aadf30a to 0d36184 Compare August 30, 2026 06:40
@Peefy
Peefy merged commit 098642d into main Aug 30, 2026
10 checks passed
@Peefy
Peefy deleted the fix/lsp-rename-test-wait branch August 30, 2026 08:34
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.

2 participants