Skip to content

Add doc regeneration rule to AGENTS.md#837

Open
BeArchiTek wants to merge 6 commits intostablefrom
bkr-agents-regenerate-docs
Open

Add doc regeneration rule to AGENTS.md#837
BeArchiTek wants to merge 6 commits intostablefrom
bkr-agents-regenerate-docs

Conversation

@BeArchiTek
Copy link
Contributor

@BeArchiTek BeArchiTek commented Feb 19, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Schema export CLI command now available to export user-defined schemas to YAML files organized by namespace, automatically excluding restricted namespaces.
    • New TRACKING client mode added for enhanced operational capabilities.
  • Documentation

    • Updated guidelines for CLI commands and SDK configuration workflows.
  • Add reminder to run invoke generate-sdk generate-infrahubctl after changing CLI commands or SDK config so generated docs stay in sync

BeArchiTek and others added 2 commits February 18, 2026 15:06
Adds `infrahubctl schema export` to fetch user-defined schemas from an
Infrahub server and write them as YAML files (one per namespace).

Restricted namespaces (Core, Builtin, Internal, etc.) and auto-generated
types (ProfileSchemaAPI, TemplateSchemaAPI) are excluded by default.
RESTRICTED_NAMESPACES is mirrored from the Infrahub server constants so
the server can later consume it from the SDK.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remind agents to run `invoke generate-sdk generate-infrahubctl`
after changing CLI commands or SDK config so generated docs stay
in sync.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@BeArchiTek BeArchiTek requested a review from a team as a code owner February 19, 2026 08:53
@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Walkthrough

The changes introduce a schema export capability to the Infrahub CLI. A new constant RESTRICTED_NAMESPACES is added to define server-reserved namespace names. The InfrahubClientMode enum is expanded with a TRACKING mode. A new export CLI command is implemented in the schema management module to export user-defined schemas as YAML files organized by namespace, excluding certain restricted namespaces and internal fields. Corresponding unit tests are added to validate export behavior including namespace filtering and directory handling. Additionally, documentation is updated to include a guideline for running a generation command after CLI or SDK config modifications.

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title focuses narrowly on the AGENTS.md documentation change, but the changeset includes significant functional additions: a new schema export CLI command with supporting constants and comprehensive tests. Update the title to reflect the main change: consider 'Add schema export CLI command and documentation regeneration reminder' to accurately represent the scope of work.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The pull request description is severely incomplete, missing most required sections from the template including What changed, How to review, How to test, Impact & rollout, and Checklist. Fill in all major template sections: provide detailed behavioral changes, implementation notes, review guidance, specific test commands with expected outputs, impact assessment on backward compatibility/performance/deployment, and complete the checklist items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 19, 2026

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 45ecc8f
Status: ✅  Deploy successful!
Preview URL: https://4070a110.infrahub-sdk-python.pages.dev
Branch Preview URL: https://bkr-agents-regenerate-docs.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 90.38462% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/ctl/schema.py 90.19% 2 Missing and 3 partials ⚠️
@@            Coverage Diff             @@
##           stable     #837      +/-   ##
==========================================
+ Coverage   80.36%   80.38%   +0.02%     
==========================================
  Files         115      115              
  Lines        9875     9926      +51     
  Branches     1504     1515      +11     
==========================================
+ Hits         7936     7979      +43     
- Misses       1417     1423       +6     
- Partials      522      524       +2     
Flag Coverage Δ
integration-tests 41.28% <19.23%> (-0.17%) ⬇️
python-3.10 51.58% <88.46%> (+0.20%) ⬆️
python-3.11 51.56% <88.46%> (?)
python-3.12 51.58% <88.46%> (+0.20%) ⬆️
python-3.13 51.56% <88.46%> (+0.16%) ⬆️
python-3.14 53.20% <88.46%> (+0.18%) ⬆️
python-filler-3.12 23.95% <1.92%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/constants.py 100.00% <100.00%> (ø)
infrahub_sdk/ctl/schema.py 64.70% <90.19%> (+9.23%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
infrahub_sdk/ctl/schema.py (1)

227-247: model_dump() serializes attributes/relationships that are immediately overwritten.

Line 229 dumps the entire schema (including attributes and relationships as plain dicts), but lines 231–245 immediately overwrite both keys with re-processed lists from the original Pydantic objects. Adding "attributes" and "relationships" to the top-level exclude set makes the intent clearer and avoids wasted serialization.

Also, wrapping model_dump() in dict() on lines 232 and 240 is redundant — model_dump() already returns a dict.

♻️ Suggested cleanup
-_SCHEMA_EXPORT_EXCLUDE: set[str] = {"hash", "hierarchy", "used_by", "id", "state"}
+_SCHEMA_EXPORT_EXCLUDE: set[str] = {"hash", "hierarchy", "used_by", "id", "state", "attributes", "relationships"}
 _FIELD_EXPORT_EXCLUDE: set[str] = {"inherited", "read_only", "allow_override", "hierarchical", "id", "state"}


 def _schema_to_export_dict(schema: NodeSchemaAPI | GenericSchemaAPI) -> dict[str, Any]:
     """Convert an API schema object to an export-ready dict (omits API-internal fields)."""
     data = schema.model_dump(exclude=_SCHEMA_EXPORT_EXCLUDE, exclude_none=True)

     data["attributes"] = [
-        dict(attr.model_dump(exclude=_FIELD_EXPORT_EXCLUDE, exclude_none=True))
+        attr.model_dump(exclude=_FIELD_EXPORT_EXCLUDE, exclude_none=True)
         for attr in schema.attributes
         if not attr.inherited
     ]
     if not data["attributes"]:
         data.pop("attributes")

     data["relationships"] = [
-        dict(rel.model_dump(exclude=_FIELD_EXPORT_EXCLUDE, exclude_none=True))
+        rel.model_dump(exclude=_FIELD_EXPORT_EXCLUDE, exclude_none=True)
         for rel in schema.relationships
         if not rel.inherited
     ]
     if not data["relationships"]:
         data.pop("relationships")

     return data
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/ctl/schema.py` around lines 227 - 247, In
_schema_to_export_dict, avoid serializing attributes/relationships twice by
adding "attributes" and "relationships" to the exclude set used in
schema.model_dump (referencing _SCHEMA_EXPORT_EXCLUDE) so model_dump doesn't
include those keys, and remove the redundant dict(...) wrappers around
attr.model_dump and rel.model_dump (they already return dicts); keep the
subsequent list comprehensions that build attributes and relationships using
_FIELD_EXPORT_EXCLUDE and the inherited check.
infrahub_sdk/constants.py (1)

3-19: Dual-source-of-truth risk is acknowledged but worth tracking.

The comment correctly notes the duplication with the server's constants. Until the server consumes this SDK list, any namespace added server-side must also be added here. Consider adding a link to the server file or a CI check to detect drift.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrahub_sdk/constants.py` around lines 3 - 19, The RESTRICTED_NAMESPACES
list is duplicated from the server and risks drifting; add a clear comment above
RESTRICTED_NAMESPACES that includes a link to the authoritative server file
(backend/infrahub/core/constants/__init__.py) and add or reference a CI check
that compares this SDK list against the server source (or fails the build when
they differ) so maintainers are alerted to changes on the server; mention the
symbol name RESTRICTED_NAMESPACES in the comment so it’s obvious what is
guarded.
tests/unit/ctl/test_schema_export.py (1)

161-181: Consider consolidating near-duplicate restricted-namespace tests.

test_schema_export_excludes_restricted_namespaces and test_schema_export_no_user_schema exercise the same code path (all nodes in restricted namespaces → early exit with warning). They differ only in node names. You could parametrize them or keep just one, freeing space for an edge-case test (e.g., a mix of restricted and user namespaces verifying that only user namespaces are exported).

Also applies to: 225-245

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/ctl/test_schema_export.py` around lines 161 - 181, Consolidate the
two near-duplicate tests test_schema_export_excludes_restricted_namespaces and
test_schema_export_no_user_schema by either parameterizing the test with
different node lists or removing one and adding an edge-case test; update the
pytest test (the function(s) calling runner.invoke(app=app, args=["export",
"--directory", ...]) and using remove_ansi_color(result.stdout)) so it accepts
multiple inputs (e.g., parametrize node sets like ["Core","Builtin","Internal"]
and another variant) or replace one with a mixed-namespace case to verify only
user namespaces are exported—adjust the HTTPX mock response setup
(_schema_response/_make_node) and assertions accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@infrahub_sdk/ctl/schema.py`:
- Around line 250-258: The callable default _default_export_directory()
currently returns a str which prevents Typer/Click from converting it to a Path
for the export() option; update _default_export_directory() so it returns a
pathlib.Path instance (not a str) so that the directory parameter in
export(directory: Path...) is a Path when the default is used, ensuring
directory.mkdir() and directory / "..." operations work correctly.

---

Nitpick comments:
In `@infrahub_sdk/constants.py`:
- Around line 3-19: The RESTRICTED_NAMESPACES list is duplicated from the server
and risks drifting; add a clear comment above RESTRICTED_NAMESPACES that
includes a link to the authoritative server file
(backend/infrahub/core/constants/__init__.py) and add or reference a CI check
that compares this SDK list against the server source (or fails the build when
they differ) so maintainers are alerted to changes on the server; mention the
symbol name RESTRICTED_NAMESPACES in the comment so it’s obvious what is
guarded.

In `@infrahub_sdk/ctl/schema.py`:
- Around line 227-247: In _schema_to_export_dict, avoid serializing
attributes/relationships twice by adding "attributes" and "relationships" to the
exclude set used in schema.model_dump (referencing _SCHEMA_EXPORT_EXCLUDE) so
model_dump doesn't include those keys, and remove the redundant dict(...)
wrappers around attr.model_dump and rel.model_dump (they already return dicts);
keep the subsequent list comprehensions that build attributes and relationships
using _FIELD_EXPORT_EXCLUDE and the inherited check.

In `@tests/unit/ctl/test_schema_export.py`:
- Around line 161-181: Consolidate the two near-duplicate tests
test_schema_export_excludes_restricted_namespaces and
test_schema_export_no_user_schema by either parameterizing the test with
different node lists or removing one and adding an edge-case test; update the
pytest test (the function(s) calling runner.invoke(app=app, args=["export",
"--directory", ...]) and using remove_ansi_color(result.stdout)) so it accepts
multiple inputs (e.g., parametrize node sets like ["Core","Builtin","Internal"]
and another variant) or replace one with a mixed-namespace case to verify only
user namespaces are exported—adjust the HTTPX mock response setup
(_schema_response/_make_node) and assertions accordingly.

@gmazoyer
Copy link
Contributor

It looks like you accidently included "Add infrahubctl schema export command" in this PR

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.

2 participants

Comments