Skip to content

refactor(scripts): extract sanitizePromptInput into a shared module#9665

Open
zied-jlassi wants to merge 1 commit into
kirodotdev:mainfrom
zied-jlassi:refactor/dedupe-sanitize-prompt-input
Open

refactor(scripts): extract sanitizePromptInput into a shared module#9665
zied-jlassi wants to merge 1 commit into
kirodotdev:mainfrom
zied-jlassi:refactor/dedupe-sanitize-prompt-input

Conversation

@zied-jlassi

Copy link
Copy Markdown

What

sanitizePromptInput was duplicated verbatim in scripts/bedrock_classifier.ts and scripts/detect_duplicates.ts. The two copies had already drifted (one carried an extra comment line), which is how duplicated logic tends to start diverging over time.

This moves the function into a single scripts/sanitize_utils.ts and imports it from both call sites, following the existing *_utils.ts convention already used by retry_utils.ts and rate_limit_utils.ts.

Why

One implementation to maintain and review, instead of two near-identical copies that can silently diverge.

Behaviour

No behaviour change — the extracted function body is identical to the previous copies.

  • npm run build (tsc): passes
  • Existing jest suite (data_models.test.ts): 13/13 pass

Notes

  • Net change: 87 duplicated lines removed, 60 added (including the shared module and its docstring).
  • The duplicated MAX_TITLE_LENGTH / MAX_BODY_LENGTH constants are intentionally left out of this PR to keep it focused on a single change.

The prompt-input sanitizer was duplicated in bedrock_classifier.ts and
detect_duplicates.ts; the two copies had already drifted by a stray comment.
Move it into a single sanitize_utils.ts and import it from both call sites so
there is one implementation to maintain and review.

No behaviour change: the extracted function body is identical to the previous
copies (verified by `npm run build` and the existing jest suite).
@zied-jlassi zied-jlassi requested review from a team as code owners June 22, 2026 14:07
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