Skip to content

Extract redactSecrets to testable module#20

Merged
Mossaka merged 3 commits intomainfrom
copilot/modify-secret-redaction-function
Oct 30, 2025
Merged

Extract redactSecrets to testable module#20
Mossaka merged 3 commits intomainfrom
copilot/modify-secret-redaction-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 30, 2025

The redactSecrets function was duplicated in test code, causing tests to validate a copy rather than the actual implementation used in production.

Changes

  • New module: src/redact-secrets.ts exports the redactSecrets function
  • Import in cli.ts: Removed local definition, imports from new module
  • Import in cli.test.ts: Removed duplicated function, imports from new module

Result

Tests now validate the production implementation. Changes to secret redaction logic will be caught by the test suite.

// Before: Function duplicated in cli.ts and cli.test.ts
const redactSecrets = (command: string): string => { /* ... */ };

// After: Single source in redact-secrets.ts, imported by both
import { redactSecrets } from './redact-secrets';
Original prompt

modify secret redaction to a functioin so unit test can properly test it

const redactSecrets = (command: string): string => {
return command
// Redact Authorization: Bearer
.replace(/(Authorization:\sBearer\s+)(\S+)/gi, '$1REDACTED*')
// Redact Authorization: (non-Bearer)
.replace(/(Authorization:\s+(?!Bearer\s))(\S+)/gi, '$1REDACTED')
// Redact tokens in environment variables
.replace(/(\w*(?:TOKEN|SECRET|PASSWORD|KEY|AUTH)\w*)=(\S+)/gi, '$1=REDACTED')
// Redact GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_)
.replace(/\b(gh[pousr]_[a-zA-Z0-9]{36,255})/g, 'REDACTED');
};

The user has attached the following files as relevant context:

  • AGENTS.md

Created from VS Code via the GitHub Pull Request extension.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Modify secret redaction to a function for testing Extract redactSecrets to testable module Oct 30, 2025
Copilot AI requested a review from Mossaka October 30, 2025 16:52
@Mossaka Mossaka marked this pull request as ready for review October 30, 2025 16:55
@Mossaka Mossaka merged commit 87c8431 into main Oct 30, 2025
3 of 6 checks passed
@Mossaka Mossaka deleted the copilot/modify-secret-redaction-function branch October 30, 2025 16:58
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