Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .valk-guard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ exclude:
- "vendor/**"
- "node_modules/**"

# Keep Go extraction strict on baseline so inferred-mapping warnings stay off.
# Use balanced Go model mapping in demos so inferred-mapping risk (VG111) can be showcased.
go_model:
mapping_mode: strict
mapping_mode: balanced

rules:
VG001:
Expand Down Expand Up @@ -52,14 +52,14 @@ rules:
enabled: true
severity: error

# This example repo is focused on VG001-VG106 demo branches.
# Dist demo branches cover VG001-VG111.
VG107:
enabled: false
enabled: true
VG108:
enabled: false
enabled: true
VG109:
enabled: false
enabled: true
VG110:
enabled: false
enabled: true
VG111:
enabled: false
enabled: true
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ valk-guard-example/
Workflow install target is configured as:

```text
github.com/valkdb/valk-guard/cmd/valk-guard@latest
github.com/valkdb/valk-guard/cmd/valk-guard.0.0-20260304065917-b9d9468a4ea3@latest
```

Rationale:

- This repository is a demo showcase; tracking latest keeps examples aligned with current built-in behavior.
- If you need strict reproducibility, pin a fixed tag in workflow `VALK_GUARD_INSTALL_REF`.
- This repository is a demo showcase, but CI is pinned to a known-good valk-guard build to keep output shape stable.
- Pinning avoids format drift that can break downstream tooling steps (for example: `Convert to reviewdog format`).
- When upgrading, bump `VALK_GUARD_INSTALL_REF` intentionally and verify the full workflow output.

## Creating Demo PRs (one rule at a time)

Expand Down
17 changes: 17 additions & 0 deletions demo/violations/dist4-vg106-111/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Dist 4: VG106-VG111

This demo bundle intentionally triggers:

- VG106 (unknown filter column)
- VG107 (unknown table reference)
- VG108 (ambiguous unqualified column)
- VG109 (orphan migration table)
- VG110 (duplicate model column mapping)
- VG111 (Go inferred table/column mapping risk)

Coverage in this bundle:

- SQL schema + query files
- Python ORM models/queries
- Python non-ORM raw SQL queries
- Go models for VG110 and VG111
16 changes: 16 additions & 0 deletions demo/violations/dist4-vg106-111/go/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package demo

// VG110User intentionally maps the same DB column twice.
type VG110User struct {
ID int64 `db:"id"`
LegacyID int64 `db:"id"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ [valk-guard] reported by reviewdog 🐶
VG110: model "vg110_users" maps column "id" multiple times (fields "ID" and "LegacyID")

Email string `db:"email"`
}

func (VG110User) TableName() string { return "vg110_users" }

// RiskyInferred intentionally relies on inferred table and column mapping.
type RiskyInferred struct {
ID int64
Email string
}
35 changes: 35 additions & 0 deletions demo/violations/dist4-vg106-111/python/orm_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from sqlalchemy import Column, Integer, String, text
from sqlalchemy.orm import DeclarativeBase, Session


class Base(DeclarativeBase):
pass


# Use table-shaped class names so synthetic SQL emitted from AST crawl aligns with schema tables.
class q_users(Base):
__tablename__ = "q_users"

id = Column(Integer, primary_key=True)
email = Column(String(255), nullable=False)


class q_orders(Base):
__tablename__ = "q_orders"

id = Column(Integer, primary_key=True)
user_id = Column(Integer, nullable=False)


def orm_unknown_filter_column(session: Session):
return session.query(q_users.id).filter(text("ghost_col = 1")).limit(1).all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [valk-guard] reported by reviewdog 🐶
VG106: filter predicate column "ghost_col" not found in table "q_users" schema; check predicate/group/order columns in schema/model mappings | Origin: SQLAlchemy query builder | Query: SELECT "q_users"."id" FROM "q_users" WHERE ghost_col = 1 LIMIT 1



def orm_ambiguous_projection_column(session: Session):
return (
session.query(text("id"))
.select_from(q_users)
.join(q_orders, q_users.id == q_orders.user_id)
.limit(1)
.all()
Comment on lines +30 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [valk-guard] reported by reviewdog 🐶
VG107: table "synthetic_model" referenced in query not found in schema | Origin: SQLAlchemy query builder | Query: SELECT "id" FROM synthetic_model JOIN "q_orders" ON 1=1 LIMIT 1

)
24 changes: 24 additions & 0 deletions demo/violations/dist4-vg106-111/python/raw_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from sqlalchemy import text
from sqlalchemy.orm import Session


def raw_unknown_filter_column(session: Session):
return session.execute(text("SELECT q_users.id FROM q_users WHERE ghost_col = 1 LIMIT 1")).all()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [valk-guard] reported by reviewdog 🐶
VG106: filter predicate column "ghost_col" not found in table "q_users" schema; check predicate/group/order columns in schema/model mappings | Query: SELECT q_users.id FROM q_users WHERE ghost_col = 1 LIMIT 1



def raw_unknown_table_reference(session: Session):
return session.execute(
text(
"SELECT q_users.id FROM q_users "
"INNER JOIN ghost_orders ON q_users.id = ghost_orders.user_id LIMIT 1"
)
).all()
Comment on lines +10 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [valk-guard] reported by reviewdog 🐶
VG107: table "ghost_orders" referenced in query not found in schema | Query: SELECT q_users.id FROM q_users INNER JOIN ghost_orders ON q_users.id = ghost_orders.user_i...



def raw_ambiguous_unqualified_column(session: Session):
return session.execute(
text(
"SELECT id FROM q_users "
"INNER JOIN q_orders ON q_users.id = q_orders.user_id LIMIT 1"
)
).all()
Comment on lines +19 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ [valk-guard] reported by reviewdog 🐶
VG108: projection column "id" is ambiguous across tables q_orders, q_users; qualify it with a table alias | Query: SELECT id FROM q_users INNER JOIN q_orders ON q_users.id = q_orders.user_id LIMIT 1

3 changes: 3 additions & 0 deletions demo/violations/dist4-vg106-111/sql/query_rules.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT q_users.id FROM q_users WHERE ghost_col = 1 LIMIT 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [valk-guard] reported by reviewdog 🐶
VG106: filter predicate column "ghost_col" not found in table "q_users" schema; check predicate/group/order columns in schema/model mappings | Query: SELECT q_users.id FROM q_users WHERE ghost_col = 1 LIMIT 1

SELECT q_users.id FROM q_users INNER JOIN ghost_orders ON q_users.id = ghost_orders.user_id LIMIT 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚫 [valk-guard] reported by reviewdog 🐶
VG107: table "ghost_orders" referenced in query not found in schema | Query: SELECT q_users.id FROM q_users INNER JOIN ghost_orders ON q_users.id = ghost_orders.user_i...

SELECT id FROM q_users INNER JOIN q_orders ON q_users.id = q_orders.user_id LIMIT 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ [valk-guard] reported by reviewdog 🐶
VG108: projection column "id" is ambiguous across tables q_orders, q_users; qualify it with a table alias | Query: SELECT id FROM q_users INNER JOIN q_orders ON q_users.id = q_orders.user_id LIMIT 1

18 changes: 18 additions & 0 deletions demo/violations/dist4-vg106-111/sql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE q_users (
id INTEGER PRIMARY KEY,
email TEXT NOT NULL
);

CREATE TABLE q_orders (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES q_users(id)
);

CREATE TABLE vg110_users (
id INTEGER PRIMARY KEY,
email TEXT NOT NULL
);

CREATE TABLE vg109_orphan (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ [valk-guard] reported by reviewdog 🐶
VG109: migration table "vg109_orphan" has no matching model mapping

id INTEGER PRIMARY KEY
);