Skip to content

fix: complete @objectstack/objectql mock and fix bridge driver naming#392

Merged
hotlong merged 3 commits intomainfrom
copilot/fix-build-and-test-again
Feb 14, 2026
Merged

fix: complete @objectstack/objectql mock and fix bridge driver naming#392
hotlong merged 3 commits intomainfrom
copilot/fix-build-and-test-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 14, 2026

All CLI sync command tests fail with app.datasource is not a function. Additional test failures in project-tracker and enterprise-erp were masked by turbo cache.

Two root causes:

Bridge driver naming (packages/foundation/core/src/app.ts)

The constructor conditionally set driver.name = configKey only when !driver.name. Since SqlDriver declares readonly name = 'SqlDriver' (truthy), drivers were registered under their class name instead of the config key, so datasource('default') never resolved.

// Before: skipped for drivers with existing name
if (!(driver as any).name) {
  (driver as any).name = name;
}

// After: always use config key as driver name
(driver as any).name = name;

Incomplete mock (packages/foundation/core/test/__mocks__/@objectstack/objectql.ts)

The mock ObjectQL class was missing methods and behaviors present in the upstream engine:

  • Missing methods: datasource(), getDriverByName(), on() (alias for registerHook), count() on context objects
  • Missing init() behavior: upstream calls driver.connect() + driver.init(objects) — mock was a no-op
  • No CRUD hooks: create/update/delete operations bypassed the hook system entirely (only find triggered hooks)
  • Missing context shape: hooks expect ctx.data, ctx.user, ctx.previousData as top-level properties

Result: 66/66 turbo tasks pass (was 63/65 with 4 visible CLI failures + hidden failures behind cache).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fastdl.mongodb.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/objectql/objectql/node_modules/.bin/../vitest/vitest.mjs run sh k/_t�� node esbuild.js --production (dns block)
  • fonts.googleapis.com
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /home/REDACTED/work/objectql/objectql/node_modules/.pnpm/next@16.1.6_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/next/dist/compiled/jest-worker/processChild.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

fix build and test


💡 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.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 14, 2026

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

Project Deployment Actions Updated (UTC)
objectql Ready Ready Preview, Comment Feb 14, 2026 2:14pm

Request Review

…stack/objectql mock and fix bridge driver naming

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix build and test issues fix: complete @objectstack/objectql mock and fix bridge driver naming Feb 14, 2026
Copilot AI requested a review from hotlong February 14, 2026 14:18
@hotlong hotlong marked this pull request as ready for review February 14, 2026 14:31
Copilot AI review requested due to automatic review settings February 14, 2026 14:31
@hotlong hotlong merged commit 696597d into main Feb 14, 2026
2 checks passed
@hotlong hotlong deleted the copilot/fix-build-and-test-again branch February 14, 2026 14:31
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

Fixes ObjectQL bridge + test mock behavior so CLI sync and related tests can resolve datasources and exercise the same hook/middleware paths as upstream @objectstack/objectql.

Changes:

  • Always set driver.name to the datasource config key in the ObjectQL bridge so datasource('default') resolves correctly.
  • Expand the @objectstack/objectql test mock to include missing engine APIs (init(), datasource(), getDriverByName(), on()) and CRUD hook execution for mutations.
  • Add count() to mock repositories with a driver-backed implementation + fallback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/foundation/core/src/app.ts Forces datasource driver naming to match config keys to make datasource(name) lookups work.
packages/foundation/core/test/mocks/@objectstack/objectql.ts Completes the upstream-like mock API and adds hook/middleware behavior around CRUD operations.

// Fetch previous data for hooks that need it
let previousData: any;
if (driver?.findOne) {
try { previousData = await driver.findOne(name, { _id: id }); } catch (_e) { /* ignore */ }
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

driver.findOne is being called with { _id: id } as the id argument. All in-repo drivers use the signature findOne(objectName, id, query?, options?), so this call will look up a record with id "[object Object]" and previousData will always be undefined, breaking hooks that rely on it (e.g., multitenancy/validator). Call driver.findOne(name, id, undefined, options) (or driver.findOne(name, id) if options aren’t needed) to fetch the prior record.

Suggested change
try { previousData = await driver.findOne(name, { _id: id }); } catch (_e) { /* ignore */ }
try { previousData = await driver.findOne(name, id, undefined, options); } catch (_e) { /* ignore */ }

Copilot uses AI. Check for mistakes.
Comment on lines +227 to +230
let previousData: any;
if (driver?.findOne) {
try { previousData = await driver.findOne(name, { _id: id }); } catch (_e) { /* ignore */ }
}
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

Same issue as update(): driver.findOne(name, { _id: id }) passes an object into the id parameter, so drivers won’t return the existing record and previousData will be missing in before/afterDelete hooks. Use driver.findOne(name, id, undefined, options) (or driver.findOne(name, id)) instead.

Copilot uses AI. Check for mistakes.
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.

3 participants