Skip to content

[DO NOT MERGE] SCAL-227566 Test PR for require-tests check - #747

Open
tushardeepakts wants to merge 2 commits into
SCAL-227566from
SCAL-227566-test-check
Open

tushardeepakts wants to merge 2 commits into
SCAL-227566from
SCAL-227566-test-check

Conversation

@tushardeepakts

Copy link
Copy Markdown
Collaborator

No description provided.

tushardeepakts and others added 2 commits November 13, 2026 11:34
A spec outside src/ (e.g. scripts/*.spec.js) does not test SDK code, so
it must not satisfy the rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tushardeepakts
tushardeepakts requested a review from a team as a code owner November 13, 2026 06:19
@tushardeepakts
tushardeepakts changed the base branch from main to SCAL-227566 November 13, 2026 06:20

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new script, check-tests-included.js, along with its unit tests, to ensure that any changes to the SDK source files are accompanied by corresponding test updates. It also configures Jest coverage for this script and adds a check-tests command to package.json. The code review feedback is highly constructive, focusing on improving security and robustness. Specifically, it recommends replacing execSync with execFileSync to prevent potential command injection vulnerabilities, wrapping the main function in a try-catch block for graceful error handling, and updating the unit tests to align with these changes.

I am having trouble creating individual review comments. Click here to see my feedback.

scripts/check-tests-included.js (7)

security-high high

Use execFileSync instead of execSync to avoid spawning a shell, which reduces the risk of shell injection vulnerabilities when executing commands with external inputs (like baseRef).

const { execFileSync } = require('child_process');

scripts/check-tests-included.js (24-29)

security-high high

Use execFileSync to safely execute the git command without shell interpolation.

function getChangedFiles(baseRef) {
    const out = execFileSync('git', ['diff', '--name-only', '--diff-filter=d', 'origin/' + baseRef + '...HEAD'], {
        encoding: 'utf8',
    });
    return out.split('\n').map((s) => s.trim()).filter(Boolean);
}

scripts/check-tests-included.js (31-41)

medium

Wrap the main function execution in a try-catch block to handle any potential errors from getChangedFiles (such as git errors in shallow clones) gracefully, printing a clean error message and exiting with a non-zero code.

function main() {
    try {
        const result = check(getChangedFiles(process.env.BASE_REF || 'main'));
        if (result.ok) {
            console.log('✓ ' + result.reason);
            return 0;
        }
        console.error('✗ This PR changes source code but adds or updates no tests (*.spec.ts):');
        result.src.forEach((f) => console.error('   - ' + f));
        console.error("Add tests, or ask a reviewer to add the 'skip-test-check' label.");
        return 1;
    } catch (error) {
        console.error('✗ Failed to check changed files:', error.message);
        return 1;
    }
}

scripts/check-tests-included.spec.js (1-2)

medium

Update the mock and import to use execFileSync instead of execSync to align with the implementation changes.

jest.mock('child_process');
const { execFileSync } = require('child_process');

scripts/check-tests-included.spec.js (30-37)

medium

Update the test assertions to mock and verify execFileSync with the correct arguments.

    test('getChangedFiles diffs against the base branch and parses output', () => {
        execFileSync.mockReturnValue('src/a.ts\nsrc/a.spec.ts\n');
        expect(getChangedFiles('release')).toEqual(['src/a.ts', 'src/a.spec.ts']);
        expect(execFileSync).toHaveBeenCalledWith(
            'git',
            ['diff', '--name-only', '--diff-filter=d', 'origin/release...HEAD'],
            { encoding: 'utf8' },
        );
    });

scripts/check-tests-included.spec.js (39-46)

medium

Update the mock calls to use execFileSync instead of execSync.

    test('main returns 1 when tests are missing and 0 when present', () => {
        jest.spyOn(console, 'error').mockImplementation(() => {});
        jest.spyOn(console, 'log').mockImplementation(() => {});
        execFileSync.mockReturnValue('src/a.ts\n');
        expect(main()).toBe(1);
        execFileSync.mockReturnValue('src/a.ts\nsrc/a.spec.ts\n');
        expect(main()).toBe(0);
    });

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@thoughtspot/visual-embed-sdk@747

commit: 686fe6e

This branch has not been deployed

No deployments
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