Skip to content

Guard driver.clear access in TCK test hooks#307

Merged
hotlong merged 12 commits into
mainfrom
copilot/fix-action-run-issue-again
Feb 2, 2026
Merged

Guard driver.clear access in TCK test hooks#307
hotlong merged 12 commits into
mainfrom
copilot/fix-action-run-issue-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 2, 2026

The driver-tck framework crashes with TypeError: Cannot read properties of undefined (reading 'clear') when createDriver() fails during test initialization. This masks the actual failure (e.g., missing dependencies) with a secondary crash in cleanup.

Changes

Added null guards before accessing driver.clear in test lifecycle hooks:

// Before
beforeEach(async () => {
    driver = createDriver();
    if (driver.clear) {
        await driver.clear();
    }
    // ...
});

// After  
beforeEach(async () => {
    driver = createDriver();
    if (driver && driver.clear) {
        await driver.clear();
    }
    // ...
});

Applied to both beforeEach and afterEach hooks in packages/tools/driver-tck/src/index.ts.

Original prompt

引用: https://github.com/objectstack-ai/objectql/actions/runs/21578298624/job/62170250257#step:9:1


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectql Ready Ready Preview, Comment Feb 2, 2026 7:32am

Request Review

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with action run process Guard driver.clear access in TCK test hooks Feb 2, 2026
Copilot AI requested a review from hotlong February 2, 2026 05:25
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2026

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2026

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

Copilot AI and others added 3 commits February 2, 2026 05:35
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2026

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

Copilot AI and others added 2 commits February 2, 2026 06:29
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2026

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

@hotlong hotlong marked this pull request as ready for review February 2, 2026 06:53
Copilot AI review requested due to automatic review settings February 2, 2026 06:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds defensive null checks to prevent crashes in the driver-tck test framework when driver initialization fails. The primary change guards driver.clear access in test lifecycle hooks to prevent TypeError exceptions that mask actual initialization failures.

Changes:

  • Added null guards before accessing driver.clear in beforeEach and afterEach hooks
  • Updated SQL driver test to use sqlite3 client instead of better-sqlite3
  • Modified Redis driver's create method to prevent duplicate ID insertion

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/tools/driver-tck/src/index.ts Added driver && null checks before accessing driver.clear in test hooks
packages/drivers/sql/test/tck.test.ts Changed SQLite client library and restructured test lifecycle hooks
packages/drivers/redis/src/index.ts Added duplicate ID prevention using Redis SET NX option

Comment on lines +60 to +63
// Close database connection
if (driver && driver['knex']) {
await driver['knex'].destroy();
}
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Accessing private member knex using bracket notation is fragile and bypasses type safety. Consider exposing a close() or destroy() method on the driver interface to properly handle cleanup.

Suggested change
// Close database connection
if (driver && driver['knex']) {
await driver['knex'].destroy();
}
// Close database connection using driver's public API if available
if (!driver) {
return;
}
const closable = driver as unknown as {
destroy?: () => Promise<void> | void;
close?: () => Promise<void> | void;
};
if (typeof closable.destroy === 'function') {
await closable.destroy();
} else if (typeof closable.close === 'function') {
await closable.close();
}

Copilot uses AI. Check for mistakes.
Copilot AI and others added 4 commits February 2, 2026 06:55
- Add automatic created_at/updated_at timestamps in create method
- Change update method to use findOneAndUpdate and return full document
- Preserve created_at in update (don't allow it to be modified)
- Fix insertOne/deleteOne to not pass empty options object
- Update tests to use findOneAndUpdate mock instead of updateOne

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
- Import FindOneAndUpdateOptions from mongodb package
- Replace 'any' type with proper FindOneAndUpdateOptions type
- Maintains all functionality while improving type safety

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@github-actions github-actions Bot added the size/M label Feb 2, 2026
@hotlong hotlong merged commit 2dfb0fc into main Feb 2, 2026
4 checks passed
@hotlong hotlong deleted the copilot/fix-action-run-issue-again branch February 2, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants