chore: add vitest + first unit tests (prompt-sanitize, town-code, town/events)#34
Open
omjeem wants to merge 4 commits into
Open
chore: add vitest + first unit tests (prompt-sanitize, town-code, town/events)#34omjeem wants to merge 4 commits into
omjeem wants to merge 4 commits into
Conversation
Member
|
hey @omjeem can you rebase this branch with the main |
omjeem
force-pushed
the
test/add-vitest-and-first-unit-tests
branch
from
July 8, 2026 15:55
b481374 to
57cc134
Compare
Contributor
Author
|
Rebased on latest main and pushed 👍 Tests + typecheck green. |
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.
Summary
Adds a test runner to the repo (there is currently no test framework configured and no
testscript in any package) and a first suite of 61 unit tests for three pure, security-relevant modules inapps/web.Test setup - mirrored from RedPlanetHQ/core
The configuration intentionally replicates the testing environment of the main
RedPlanetHQ/corerepo so both projects stay consistent:^3.2.0+vite-tsconfig-paths^4.2.1- the same two packages and versions core'sapps/webappuses.apps/web/vitest.config.tsis a mirror of core'sapps/webapp/vitest.config.ts:tsconfigPaths()plugin,environment: "node", with the include pattern adapted from theirapp/**source root to this app'ssrc/**/*.test.ts(x)."test": "vitest run"script in the app'spackage.json, same as core.__tests__/folders colocated with source, files named<module>.test.ts.testtask - the runner lives in the app package only.Tests added
src/lib/__tests__/prompt-sanitize.test.tsSpeaker:-line injection stripping insafeBlock, newline flattening insafeInline, C0/DEL control-char removal, all reserved-label variants, length capssrc/lib/__tests__/town-code.test.tsnullfor every fieldsrc/lib/town/__tests__/events.test.tssignBodyagainst a hardcoded known-answer HMAC vector,verifyHmac(tampered body, wrong secret, wrong length, invalid hex), fullparseEnvelopevalidation for both event typesNotes:
@town/dbis mocked in the events suite (it instantiatesPrismaClientat import time); the functions under test never touch it, so the suite runs with no database or generated client.safeBlockreplaces\rwith a space before line-splitting (CRLF →" \n"), and topic-field validation errors don't include the array path in the message.How to run
pnpm --filter @town/web test