agentboard — review

Target: packages/mcp-server-supabase/src/tools/database-operation-tools.ts Intent: Issue (the problem): list_tables verbose output represented composite foreign keys incorrectly. Originally a pg-meta SQL cross-join paired every source column with every target column (N^2 rows, fabricating relationships). An interim fix paired columns positionally but still emitted one row per column pair, so nothing signaled that two rows belong to one atomic constraint vs two independent FKs.
0 confirmed gap(s) · 12 covered/handled · 1 test didn't run · 13 behaviors reviewed
In the PostgreSQL relational schema metadata/list_tables verbose domain, a single-column foreign key is serialized as one constraint object with one-element source_columns and target_columns arrays.already covered
already covered — covered by the existing verbose list_tables expectation for public.orders -> public.users shown in the PR diff
axis: correctness
A composite outgoing foreign key is grouped as one atomic constraint object rather than emitted as N^2 fabricated relationships or one row per column pair.already covered
already covered — covered by existing test 'composite FK is grouped as one constraint with positionally ordered columns'
axis: correctness
Composite foreign key column arrays must be ordered by constraint-definition ordinality even when that order differs from the tables' physical column attnum order.test didn't run
not covered by existing tests — none found; the existing composite test uses physical column order matching the FK order
axis: correctness
Observed: Error: Test timed out in 30000ms.
test the agent wrote
test('composite FK column order follows constraint ordinality rather than physical column order', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(`
    create table parent (
      x int,
      y int,
      primary key (y, x)
    );
    create table child (
      a int,
      b int,
      constraint child_parent_fk
        foreign key (b, a) references parent (y, x)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const childTable = result.tables.find(
    (t: { name: string }) => t.name === 'public.child'
  );
  expect(childTable).toBeDefined();

  const constraints = childTable.foreign_key_constraints ?? [];
  expect(constraints).toHaveLength(1);
  expect(constraints).toEqual([
    {
      name: 'child_parent_fk',
      source_table: 'public.child',
      source_columns: ['b', 'a'],
      target_table: 'public.parent',
      target_columns: ['y', 'x'],
    },
  ]);
});
A table listed as the target of a foreign key includes that incoming relationship, and source_table identifies the referencing table.handled
not covered by existing tests — none found; existing assertions inspect only the referencing child table
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('target table includes incoming foreign key constraint with source_table', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(`
    create table parent (
      id int primary key
    );
    create table child (
      parent_id int,
      constraint child_parent_fk
        foreign key (parent_id) references parent (id)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const parentTable = result.tables.find(
    (t: { name: string }) => t.name === 'public.parent'
  );
  expect(parentTable).toBeDefined();

  const constraints = parentTable.foreign_key_constraints ?? [];
  expect(constraints).toHaveLength(1);
  expect(constraints).toEqual([
    {
      name: 'child_parent_fk',
      source_table: 'public.child',
      source_columns: ['parent_id'],
      target_table: 'public.parent',
      target_columns: ['id'],
    },
  ]);
});
Multiple independent foreign key constraints between the same two tables remain separate constraint objects and are not merged into one composite relationship.handled
not covered by existing tests — none found
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('multiple independent FKs between same tables are separate constraints', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(`
    create table parent (
      id int primary key
    );
    create table child (
      primary_parent_id int,
      backup_parent_id int,
      constraint child_primary_parent_fk
        foreign key (primary_parent_id) references parent (id),
      constraint child_backup_parent_fk
        foreign key (backup_parent_id) references parent (id)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const childTable = result.tables.find(
    (t: { name: string }) => t.name === 'public.child'
  );
  expect(childTable).toBeDefined();

  const constraints = [...(childTable.foreign_key_constraints ?? [])].sort(
    (a, b) => a.name.localeCompare(b.name)
  );
  expect(constraints).toHaveLength(2);
  expect(constraints).toEqual([
    {
      name: 'child_backup_parent_fk',
      source_table: 'public.child',
      source_columns: ['backup_parent_id'],
      target_table: 'public.parent',
      target_columns: ['id'],
    },
    {
      name: 'child_primary_parent_fk',
      source_table: 'public.child',
      source_columns: ['primary_parent_id'],
      target_table: 'public.parent',
      target_columns: ['id'],
    },
  ]);
});
Foreign keys crossing schema boundaries are represented with schema-qualified source_table and target_table names.handled
not covered by existing tests — none found; existing FK tests use only public schema tables
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('cross-schema foreign keys use schema-qualified source and target tables', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(`
    create schema app;
    create table public.accounts (
      id int primary key
    );
    create table app.orders (
      account_id int,
      constraint orders_account_fk
        foreign key (account_id) references public.accounts (id)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public', 'app'],
      verbose: true,
    },
  });

  const orderTable = result.tables.find(
    (t: { name: string }) => t.name === 'app.orders'
  );
  expect(orderTable).toBeDefined();

  const constraints = orderTable.foreign_key_constraints ?? [];
  expect(constraints).toHaveLength(1);
  expect(constraints).toEqual([
    {
      name: 'orders_account_fk',
      source_table: 'app.orders',
      source_columns: ['account_id'],
      target_table: 'public.accounts',
      target_columns: ['id'],
    },
  ]);
});
A foreign key that references a unique constraint rather than a primary key is still listed as a normal foreign key constraint with the referenced target column.handled
not covered by existing tests — none found; existing tests reference primary keys only
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('foreign key referencing a unique constraint is listed', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(`
    create table parent (
      id int primary key,
      code text unique
    );
    create table child (
      parent_code text,
      constraint child_parent_code_fk
        foreign key (parent_code) references parent (code)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const childTable = result.tables.find(
    (t: { name: string }) => t.name === 'public.child'
  );
  expect(childTable).toBeDefined();

  const constraints = childTable.foreign_key_constraints ?? [];
  expect(constraints).toHaveLength(1);
  expect(constraints).toEqual([
    {
      name: 'child_parent_code_fk',
      source_table: 'public.child',
      source_columns: ['parent_code'],
      target_table: 'public.parent',
      target_columns: ['code'],
    },
  ]);
});
A self-referential foreign key is represented once with the same schema-qualified table as both source_table and target_table.handled
not covered by existing tests — none found
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('self-referential foreign key is represented once', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(`
    create table employee (
      id int primary key,
      manager_id int,
      constraint employee_manager_fk
        foreign key (manager_id) references employee (id)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const employeeTable = result.tables.find(
    (t: { name: string }) => t.name === 'public.employee'
  );
  expect(employeeTable).toBeDefined();

  const constraints = employeeTable.foreign_key_constraints ?? [];
  expect(constraints).toHaveLength(1);
  expect(constraints).toEqual([
    {
      name: 'employee_manager_fk',
      source_table: 'public.employee',
      source_columns: ['manager_id'],
      target_table: 'public.employee',
      target_columns: ['id'],
    },
  ]);
});
A verbose table with no foreign keys does not fabricate any foreign_key_constraints.handled
not covered by existing tests — none found specifically asserting the empty/no-relationship case
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('table with no foreign keys has no foreign key constraints', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(`
    create table standalone (
      id int primary key
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const standaloneTable = result.tables.find(
    (t: { name: string }) => t.name === 'public.standalone'
  );
  expect(standaloneTable).toBeDefined();

  const constraints = standaloneTable.foreign_key_constraints ?? [];
  expect(constraints).toHaveLength(0);
  expect(constraints).toEqual([]);
});
Repeated verbose list_tables calls for the same composite foreign key return the same grouped constraint and column order.handled
not covered by existing tests — none found
axis: consistency
Observed: test passed — the tool already does this
test the agent wrote
test('composite FK verbose output is stable across repeated list_tables calls', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(`
    create table parent (
      x int,
      y int,
      primary key (y, x)
    );
    create table child (
      a int,
      b int,
      constraint child_parent_fk
        foreign key (b, a) references parent (y, x)
    );
  `);

  const firstResult = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });
  const secondResult = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const firstChildTable = firstResult.tables.find(
    (t: { name: string }) => t.name === 'public.child'
  );
  const secondChildTable = secondResult.tables.find(
    (t: { name: string }) => t.name === 'public.child'
  );
  expect(firstChildTable).toBeDefined();
  expect(secondChildTable).toBeDefined();

  const firstConstraints = firstChildTable.foreign_key_constraints ?? [];
  const secondConstraints = secondChildTable.foreign_key_constraints ?? [];
  expect(firstConstraints).toHaveLength(1);
  expect(secondConstraints).toHaveLength(1);
  expect(firstConstraints).toEqual([
    {
      name: 'child_parent_fk',
      source_table: 'public.child',
      source_columns: ['b', 'a'],
      target_table: 'public.parent',
      target_columns: ['y', 'x'],
    },
  ]);
  expect(secondConstraints).toEqual(firstConstraints);
});
Composite foreign keys preserve target_columns in referenced-column ordinality when the referenced column order differs from the target table's physical column order.handled
not covered by existing tests — proposed by critic (2nd-pass, different model)
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('list_tables verbose preserves composite target column order when it differs from target table order', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(codeBlock`
    create table public.parent_target_order (
      parent_a integer not null,
      parent_b integer not null,
      constraint parent_target_order_key unique (parent_b, parent_a)
    );

    create table public.child_target_order (
      child_a integer not null,
      child_b integer not null,
      constraint child_parent_target_order_fkey
        foreign key (child_b, child_a)
        references public.parent_target_order (parent_b, parent_a)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const tables = [...result.tables].sort((a, b) => a.name.localeCompare(b.name));
  const tableNames = tables.map(({ name }) => name);
  expect(tableNames).toHaveLength(2);
  expect(tableNames).toEqual([
    'public.child_target_order',
    'public.parent_target_order',
  ]);

  const [child, parent] = tables;
  const expectedForeignKeys = [
    {
      name: 'child_parent_target_order_fkey',
      source_table: 'public.child_target_order',
      source_columns: ['child_b', 'child_a'],
      target_table: 'public.parent_target_order',
      target_columns: ['parent_b', 'parent_a'],
    },
  ];

  const childForeignKeys = [...(child.foreign_key_constraints ?? [])].sort((a, b) =>
    `${a.source_table}|${a.name}`.localeCompare(`${b.source_table}|${b.name}`)
  );
  expect(childForeignKeys).toHaveLength(1);
  expect(childForeignKeys).toEqual(expectedForeignKeys);

  const parentForeignKeys = [...(parent.foreign_key_constraints ?? [])].sort((a, b) =>
    `${a.source_table}|${a.name}`.localeCompare(`${b.source_table}|${b.name}`)
  );
  expect(parentForeignKeys).toHaveLength(1);
  expect(parentForeignKeys).toEqual(expectedForeignKeys);
});
Foreign key constraint names are only unique per table, so same-named constraints on different source tables must remain separate objects instead of being grouped by name.handled
not covered by existing tests — proposed by critic (2nd-pass, different model)
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('list_tables verbose keeps same-named foreign keys on different tables separate', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(codeBlock`
    create table public.same_name_parent (
      tenant_id integer not null,
      code integer not null,
      primary key (tenant_id, code)
    );

    create table public.same_name_child_one (
      id integer primary key,
      tenant_id integer not null,
      code integer not null,
      constraint same_named_parent_fkey
        foreign key (tenant_id, code)
        references public.same_name_parent (tenant_id, code)
    );

    create table public.same_name_child_two (
      id integer primary key,
      tenant_id integer not null,
      code integer not null,
      constraint same_named_parent_fkey
        foreign key (tenant_id, code)
        references public.same_name_parent (tenant_id, code)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const tables = [...result.tables].sort((a, b) => a.name.localeCompare(b.name));
  const tableNames = tables.map(({ name }) => name);
  expect(tableNames).toHaveLength(3);
  expect(tableNames).toEqual([
    'public.same_name_child_one',
    'public.same_name_child_two',
    'public.same_name_parent',
  ]);

  const [childOne, childTwo, parent] = tables;

  const childOneForeignKeys = [...(childOne.foreign_key_constraints ?? [])].sort((a, b) =>
    `${a.source_table}|${a.name}`.localeCompare(`${b.source_table}|${b.name}`)
  );
  expect(childOneForeignKeys).toHaveLength(1);
  expect(childOneForeignKeys).toEqual([
    {
      name: 'same_named_parent_fkey',
      source_table: 'public.same_name_child_one',
      source_columns: ['tenant_id', 'code'],
      target_table: 'public.same_name_parent',
      target_columns: ['tenant_id', 'code'],
    },
  ]);

  const childTwoForeignKeys = [...(childTwo.foreign_key_constraints ?? [])].sort((a, b) =>
    `${a.source_table}|${a.name}`.localeCompare(`${b.source_table}|${b.name}`)
  );
  expect(childTwoForeignKeys).toHaveLength(1);
  expect(childTwoForeignKeys).toEqual([
    {
      name: 'same_named_parent_fkey',
      source_table: 'public.same_name_child_two',
      source_columns: ['tenant_id', 'code'],
      target_table: 'public.same_name_parent',
      target_columns: ['tenant_id', 'code'],
    },
  ]);

  const parentForeignKeys = [...(parent.foreign_key_constraints ?? [])].sort((a, b) =>
    `${a.source_table}|${a.name}`.localeCompare(`${b.source_table}|${b.name}`)
  );
  expect(parentForeignKeys).toHaveLength(2);
  expect(parentForeignKeys).toEqual([
    {
      name: 'same_named_parent_fkey',
      source_table: 'public.same_name_child_one',
      source_columns: ['tenant_id', 'code'],
      target_table: 'public.same_name_parent',
      target_columns: ['tenant_id', 'code'],
    },
    {
      name: 'same_named_parent_fkey',
      source_table: 'public.same_name_child_two',
      source_columns: ['tenant_id', 'code'],
      target_table: 'public.same_name_parent',
      target_columns: ['tenant_id', 'code'],
    },
  ]);
});
When listing only the target schema, incoming foreign keys from source tables in schemas not requested are still shown on the target table with the source_table schema-qualified.handled
not covered by existing tests — proposed by critic (2nd-pass, different model)
axis: correctness
Observed: test passed — the tool already does this
test the agent wrote
test('list_tables verbose includes incoming foreign keys from schemas outside the requested schema list', async () => {
  const { callTool } = await setup();

  const org = await createOrganization({
    name: 'My Org',
    plan: 'free',
    allowed_release_channels: ['ga'],
  });

  const project = await createProject({
    name: 'Project 1',
    region: 'us-east-1',
    organization_id: org.id,
  });
  project.status = 'ACTIVE_HEALTHY';

  await project.db.exec(codeBlock`
    create schema hidden_fk_source;

    create table public.incoming_parent (
      tenant_id integer not null,
      sku text not null,
      primary key (tenant_id, sku)
    );

    create table hidden_fk_source.incoming_child (
      id integer primary key,
      tenant_id integer not null,
      sku text not null,
      constraint hidden_child_parent_fkey
        foreign key (tenant_id, sku)
        references public.incoming_parent (tenant_id, sku)
    );
  `);

  const result = await callTool({
    name: 'list_tables',
    arguments: {
      project_id: project.id,
      schemas: ['public'],
      verbose: true,
    },
  });

  const tables = [...result.tables].sort((a, b) => a.name.localeCompare(b.name));
  const tableNames = tables.map(({ name }) => name);
  expect(tableNames).toHaveLength(1);
  expect(tableNames).toEqual(['public.incoming_parent']);

  const [parent] = tables;
  const parentForeignKeys = [...(parent.foreign_key_constraints ?? [])].sort((a, b) =>
    `${a.source_table}|${a.name}`.localeCompare(`${b.source_table}|${b.name}`)
  );
  expect(parentForeignKeys).toHaveLength(1);
  expect(parentForeignKeys).toEqual([
    {
      name: 'hidden_child_parent_fkey',
      source_table: 'hidden_fk_source.incoming_child',
      source_columns: ['tenant_id', 'sku'],
      target_table: 'public.incoming_parent',
      target_columns: ['tenant_id', 'sku'],
    },
  ]);
});