From eeb8152a52e4db50b17cec2d69856a7315b8f7e0 Mon Sep 17 00:00:00 2001 From: eitam Date: Wed, 4 Mar 2026 22:43:19 -0800 Subject: [PATCH 1/3] demo(dist4): add VG106-VG111 violations and enable rules --- .valk-guard.yaml | 16 ++++++------- demo/violations/dist4-vg106-111/README.md | 17 +++++++++++++ demo/violations/dist4-vg106-111/go/models.go | 16 +++++++++++++ .../dist4-vg106-111/python/orm_models.py | 24 +++++++++++++++++++ .../dist4-vg106-111/python/raw_queries.py | 24 +++++++++++++++++++ .../dist4-vg106-111/sql/query_rules.sql | 3 +++ .../violations/dist4-vg106-111/sql/schema.sql | 18 ++++++++++++++ 7 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 demo/violations/dist4-vg106-111/README.md create mode 100644 demo/violations/dist4-vg106-111/go/models.go create mode 100644 demo/violations/dist4-vg106-111/python/orm_models.py create mode 100644 demo/violations/dist4-vg106-111/python/raw_queries.py create mode 100644 demo/violations/dist4-vg106-111/sql/query_rules.sql create mode 100644 demo/violations/dist4-vg106-111/sql/schema.sql diff --git a/.valk-guard.yaml b/.valk-guard.yaml index fa83cb8..05cabfe 100644 --- a/.valk-guard.yaml +++ b/.valk-guard.yaml @@ -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: @@ -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 diff --git a/demo/violations/dist4-vg106-111/README.md b/demo/violations/dist4-vg106-111/README.md new file mode 100644 index 0000000..ff16412 --- /dev/null +++ b/demo/violations/dist4-vg106-111/README.md @@ -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 diff --git a/demo/violations/dist4-vg106-111/go/models.go b/demo/violations/dist4-vg106-111/go/models.go new file mode 100644 index 0000000..e5308c1 --- /dev/null +++ b/demo/violations/dist4-vg106-111/go/models.go @@ -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"` + 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 +} diff --git a/demo/violations/dist4-vg106-111/python/orm_models.py b/demo/violations/dist4-vg106-111/python/orm_models.py new file mode 100644 index 0000000..1570c52 --- /dev/null +++ b/demo/violations/dist4-vg106-111/python/orm_models.py @@ -0,0 +1,24 @@ +from sqlalchemy import Column, Integer, String, text +from sqlalchemy.orm import DeclarativeBase, Session + + +class Base(DeclarativeBase): + pass + + +class QUser(Base): + __tablename__ = "q_users" + + id = Column(Integer, primary_key=True) + email = Column(String(255), nullable=False) + + +class QOrder(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(QUser.id).filter(text("ghost_col = 1")).limit(1).all() diff --git a/demo/violations/dist4-vg106-111/python/raw_queries.py b/demo/violations/dist4-vg106-111/python/raw_queries.py new file mode 100644 index 0000000..f6f5811 --- /dev/null +++ b/demo/violations/dist4-vg106-111/python/raw_queries.py @@ -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() + + +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() + + +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() diff --git a/demo/violations/dist4-vg106-111/sql/query_rules.sql b/demo/violations/dist4-vg106-111/sql/query_rules.sql new file mode 100644 index 0000000..23dee02 --- /dev/null +++ b/demo/violations/dist4-vg106-111/sql/query_rules.sql @@ -0,0 +1,3 @@ +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; +SELECT id FROM q_users INNER JOIN q_orders ON q_users.id = q_orders.user_id LIMIT 1; diff --git a/demo/violations/dist4-vg106-111/sql/schema.sql b/demo/violations/dist4-vg106-111/sql/schema.sql new file mode 100644 index 0000000..850f9f8 --- /dev/null +++ b/demo/violations/dist4-vg106-111/sql/schema.sql @@ -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 ( + id INTEGER PRIMARY KEY +); From 9742b828ade669a0fb934a1ce913fd8d705f3643 Mon Sep 17 00:00:00 2001 From: eitam Date: Wed, 4 Mar 2026 22:49:07 -0800 Subject: [PATCH 2/3] docs(ci): pin valk-guard install ref for stable reviewdog conversion --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 76ae6fb..99f0d1e 100644 --- a/README.md +++ b/README.md @@ -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) From 1342608e9d6e9745dce1ca882fba4fbb2d5ab07f Mon Sep 17 00:00:00 2001 From: eitam Date: Wed, 4 Mar 2026 23:00:44 -0800 Subject: [PATCH 3/3] demo(dist4): use true SQLAlchemy ORM query examples in ORM fixture --- .../dist4-vg106-111/python/orm_models.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/demo/violations/dist4-vg106-111/python/orm_models.py b/demo/violations/dist4-vg106-111/python/orm_models.py index 1570c52..d85aeff 100644 --- a/demo/violations/dist4-vg106-111/python/orm_models.py +++ b/demo/violations/dist4-vg106-111/python/orm_models.py @@ -6,14 +6,15 @@ class Base(DeclarativeBase): pass -class QUser(Base): +# 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 QOrder(Base): +class q_orders(Base): __tablename__ = "q_orders" id = Column(Integer, primary_key=True) @@ -21,4 +22,14 @@ class QOrder(Base): def orm_unknown_filter_column(session: Session): - return session.query(QUser.id).filter(text("ghost_col = 1")).limit(1).all() + return session.query(q_users.id).filter(text("ghost_col = 1")).limit(1).all() + + +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() + )