Repository navigation
Conversation
…ments APIAggregator interpolated user-supplied descriptions into TypeScript comments without sanitizing them, so /api/definitions and client.getTypeDefinitions() could return invalid TypeScript: - a line break in an input property description escaped the `//` comment - `*/` (e.g. a glob like `src/**/*.ts`) closed `/** */` and `/* */` comments early - the existing `.replace(/\n/g, ' ')` missed `\r`, U+2028 and U+2029, which TypeScript also treats as line terminators Add a `toCommentSafe` helper that collapses all line terminators to a space and escapes `*/` as `*\/`, and use it at every site that embeds a description. Tests: - unit: toCommentSafe behavior - generator: TS-parser validation of generateTypeScript() and the compact signature, plus a fast-check property test over arbitrary descriptions - e2e: GET /api/definitions and client.getTypeDefinitions() parse cleanly Fixes #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
generateRuntimeTypes() embedded runtime API, method and @PARAM descriptions in JSDoc without escaping `*/` or handling all line terminators -- the same class of bug as #72. Built-in metadata is clean today, so this is defensive. - Move the comment sanitizer into atp-runtime (metadata/comment-safe.ts) so runtime and server share one implementation; atp-server now imports toCommentSafe from @mondaydotcomorg/atp-runtime. - Add toCommentSafeLines() for multi-line JSDoc: splits on CRLF/CR/LF/ U+2028/U+2029 and escapes `*/` per line, preserving line structure. - Apply at the API description, method description and @PARAM sites. - Tests: runtime-types-comment-escaping.test.ts (synthetic metadata + guard that the real GENERATED_METADATA output parses), plus toCommentSafeLines unit tests. Refs #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #72
Problem
Descriptions were inserted into TypeScript comments without escaping, so
/api/definitionsandclient.getTypeDefinitions()could return invalid TypeScript://comment (TS1005)*/, e.g. a glob likesrc/**/*.ts, closed the/** */and/* */comments early (TS1131/TS1161).replace(/\n/g, ' ')missed\r, U+2028 and U+2029, which TypeScript also treats as line terminators. The issue didn't mention these.Fix
One sanitizer, now in
atp-runtime(packages/runtime/src/metadata/comment-safe.ts) so the runtime and the server share it:toCommentSafeLines(text)splits on every line terminator (\r\n,\r,\n, U+2028, U+2029) and escapes*/as*\/in each line.toCommentSafe(text)is the same thing joined into one line, for single-line comments.Where it's applied:
APIAggregator), where the reported bug was:generateFunctionTypes,generateAPINamespace,generateCompactInputType,generateCompactOutputType. Escaping runs after the existing truncation.generateRuntimeTypes): the API description (keeps its multi-line JSDoc), the method description and@paramdescriptions. The built-in metadata is clean today, so this part is defensive.Tests
All regression tests are in
__tests__/unit, so they run underyarn test:unitin CI. The vitest suites inpackages/server/__tests__ande2e/serverdon't run in CI today.__tests__/unit/comment-safe.test.ts*/, idempotence, blank lines kept, the two helpers agree__tests__/unit/aggregator-comment-escaping.test.tsgenerateTypeScript()and the compact signature through the TypeScript parser (zero syntax errors), including the exact repro from the issue; description text is kept (escaped). Adds a fast-check property test (300 runs) with arbitrary descriptions weighted toward characters that break comments__tests__/unit/runtime-types-comment-escaping.test.tsGENERATED_METADATAparses__tests__/e2e/server/definitions-comment-escaping.test.tsGET /api/definitionsandclient.getTypeDefinitions()return TypeScript that parsesfast-check(already in the lockfile throughatp-compiler) is now also a root devDependency.Mutation checks (put the old code back, confirm the tests catch it):
["", "*/", ""].Local results:
yarn test:unitpasses (268 jest + 351 atp-compiler).packages/servervitest: 111 passed. E2Eserver/definitions-comment-escaping,apiandexplorer: 30 passed.tsc --buildis clean.API change
atp-runtimenow exportstoCommentSafeandtoCommentSafeLines. This only adds exports; nothing existing changes.🤖 Generated with Claude Code