Skip to content

Feat/anonymous instances test op#6#65

Merged
Artifizer merged 4 commits intoGlobalTypeSystem:mainfrom
GeraBart:feat/anonymous_instances_test_OP#6
Mar 5, 2026
Merged

Feat/anonymous instances test op#6#65
Artifizer merged 4 commits intoGlobalTypeSystem:mainfrom
GeraBart:feat/anonymous_instances_test_OP#6

Conversation

@GeraBart
Copy link
Copy Markdown
Contributor

@GeraBart GeraBart commented Mar 5, 2026

  • tests/test_op6_schema_validation.py — added 2 new test classes for anonymous instance validation
  • refactored existing OP#6 tests to comply with coderabbitai standards
  • .gitignore — added pycache/ and logs/

Summary by CodeRabbit

  • Tests
    • Expanded schema-validation coverage with reusable schema builders, new payload scenarios, anonymous-instance validation (valid/invalid), many rejection/validation cases (invalid IDs, unknown formats, non-existent instances), and broader JSON Schema constraint checks (format, nested objects, enums, arrays).
  • Chores
    • Updated ignore patterns to exclude Python cache and logs.

Signed-off-by: GeraBart <246844849+GeraBart@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

Adds __pycache__/ and logs/ to .gitignore. Substantially expands OP#6 schema-validation tests in tests/test_op6_schema_validation.py, adding schema helper builders, payload schema constants, many new/updated test classes (including anonymous-instance flows), and broad validation and edge-case scenarios.

Changes

Cohort / File(s) Summary
Repository ignores
\.gitignore
Added __pycache__/ and logs/ to the ignore list.
OP#6 schema validation tests
tests/test_op6_schema_validation.py
Major test additions and refactor: added helper builders _base_event_schema(schema_id, id_property=None) and _derived_event_schema(base_id, derived_id, payload_schema), payload schema constants (ORDER_PLACED_PAYLOAD_SCHEMA, REQUIRED_FIELD_PAYLOAD_SCHEMA), many new/expanded test classes (including anonymous-instance valid/invalid flows), extended schema-registration/validation scenarios (invalid IDs, missing/non-GTS IDs, unknown formats, non-existent instances), and added JSON Schema constraint tests (format, enums, nested objects, arrays). Review focus: new helper functions, test logic, schema registration and anonymous-instance workflows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through commits, a flurry of delight,
Hid caches and logs out of sight.
I stitched up schemas, helpers in tow,
Tests danced with anon IDs in tow.
A carrot for CI — now off they go!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: adding test classes for anonymous instance validation in the OP#6 schema validation tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
tests/test_op6_schema_validation.py (1)

640-787: Consider extracting shared schema builders to reduce duplication.

Both new classes repeat near-identical base/derived schema payload construction. A small helper (or fixture-like builder) will reduce drift and make future OP#6 variants easier to add.

♻️ Refactor sketch
+def _base_event_schema(schema_id: str) -> dict:
+    return {
+        "$$id": schema_id,
+        "$$schema": "http://json-schema.org/draft-07/schema#",
+        "type": "object",
+        "required": ["id", "type", "tenantId", "occurredAt"],
+        "properties": {
+            "type": {"type": "string"},
+            "id": {"type": "string", "format": "uuid"},
+            "tenantId": {"type": "string", "format": "uuid"},
+            "occurredAt": {"type": "string", "format": "date-time"},
+            "payload": {"type": "object"},
+        },
+        "additionalProperties": False,
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_op6_schema_validation.py` around lines 640 - 787, The test files
duplicate the same base/derived JSON-schema construction across
TestCaseTestOp6ValidateInstance_AnonymousInstance and
TestCaseTestOp6ValidateInstance_AnonymousInstance_Invalid; extract the repeated
JSON payloads into reusable builder helpers (e.g., functions like
build_base_event_schema() and build_derived_event_schema(type_id, payload_spec))
and call those from the teststeps instead of inlining the large dicts; update
the RunRequest blocks titled "register base event schema" and "register derived
event schema" to .with_json(build_base_event_schema()) and
.with_json(build_derived_event_schema(...)) respectively (use the existing $$id
constants such as "gts://gts.x.test6anon.events.type.v1~" and the derived ids
like "gts://gts.x.test6anon.events.type.v1~x.commerce.orders.order_placed.v1.0~"
so tests keep same semantics).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/test_op6_schema_validation.py`:
- Around line 640-787: The test files duplicate the same base/derived
JSON-schema construction across
TestCaseTestOp6ValidateInstance_AnonymousInstance and
TestCaseTestOp6ValidateInstance_AnonymousInstance_Invalid; extract the repeated
JSON payloads into reusable builder helpers (e.g., functions like
build_base_event_schema() and build_derived_event_schema(type_id, payload_spec))
and call those from the teststeps instead of inlining the large dicts; update
the RunRequest blocks titled "register base event schema" and "register derived
event schema" to .with_json(build_base_event_schema()) and
.with_json(build_derived_event_schema(...)) respectively (use the existing $$id
constants such as "gts://gts.x.test6anon.events.type.v1~" and the derived ids
like "gts://gts.x.test6anon.events.type.v1~x.commerce.orders.order_placed.v1.0~"
so tests keep same semantics).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e926c43f-1c32-4b1a-8bac-2597c43092db

📥 Commits

Reviewing files that changed from the base of the PR and between 4ed5421 and 2845186.

📒 Files selected for processing (2)
  • .gitignore
  • tests/test_op6_schema_validation.py

Copy link
Copy Markdown

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/test_op6_schema_validation.py (1)

187-205: ⚠️ Potential issue | 🔴 Critical

Use the same instance ID for registration and validation in the invalid-instance test.

Line 189 registers ...order_placed...some_event2..., but Line 204 validates ...invalid.event...some_event2.... This currently tests a lookup mismatch rather than payload-schema failure.

Suggested fix
-                "id": "gts.x.test6.events.type.v1~x.commerce.orders.order_placed.v1.0~x.y._.some_event2.v1.0",
+                "id": "gts.x.test6.events.type.v1~x.test6.invalid.event.v1.0~x.y._.some_event2.v1.0",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_op6_schema_validation.py` around lines 187 - 205, The
invalid-instance test is using two different instance IDs (the registration uses
"gts.x.test6.events.type.v1~x.commerce.orders.order_placed.v1.0~x.y._.some_event2.v1.0"
while the validation uses
"gts.x.test6.events.type.v1~x.test6.invalid.event.v1.0~x.y._.some_event2.v1.0"),
causing a lookup mismatch; update the Step with RunRequest titled "validate
instance should fail" so its .with_json payload's "instance_id" exactly matches
the id used in the earlier registration (the string starting with
"gts.x.test6.events.type.v1~x.commerce.orders.order_placed.v1.0~x.y._.some_event2.v1.0")
so the test exercises payload-schema validation rather than a missing-instance
lookup.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/test_op6_schema_validation.py`:
- Around line 17-32: The helper _base_event_schema currently forces the "id"
property to have format "uuid", which breaks tests that use well-known/chained
GTS IDs; update _base_event_schema to accept an argument (e.g., id_schema or
allow_well_known flag) and use that to set the "id" property schema (either
{"type":"string","format":"uuid"} or a more permissive {"type":"string"} that
allows chained GTS IDs), then update the anonymous-callsite test classes
mentioned in the file to call _base_event_schema with the permissive id option
where they use well-known IDs.

---

Outside diff comments:
In `@tests/test_op6_schema_validation.py`:
- Around line 187-205: The invalid-instance test is using two different instance
IDs (the registration uses
"gts.x.test6.events.type.v1~x.commerce.orders.order_placed.v1.0~x.y._.some_event2.v1.0"
while the validation uses
"gts.x.test6.events.type.v1~x.test6.invalid.event.v1.0~x.y._.some_event2.v1.0"),
causing a lookup mismatch; update the Step with RunRequest titled "validate
instance should fail" so its .with_json payload's "instance_id" exactly matches
the id used in the earlier registration (the string starting with
"gts.x.test6.events.type.v1~x.commerce.orders.order_placed.v1.0~x.y._.some_event2.v1.0")
so the test exercises payload-schema validation rather than a missing-instance
lookup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3df6ca34-e352-40cd-9e1e-10007019af9a

📥 Commits

Reviewing files that changed from the base of the PR and between 2845186 and 2cbb879.

📒 Files selected for processing (1)
  • tests/test_op6_schema_validation.py

Comment thread tests/test_op6_schema_validation.py Outdated
@GeraBart GeraBart force-pushed the feat/anonymous_instances_test_OP#6 branch from 2cbb879 to 775d237 Compare March 5, 2026 05:32
Copy link
Copy Markdown

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/test_op6_schema_validation.py (1)

191-191: ⚠️ Potential issue | 🟠 Major

Fix mismatched registered instance ID in invalid-instance test.

Line 191 registers id under the ...order_placed... chain, but validation later targets ...x.test6.invalid.event... (Line 206). This can make the test pass for the wrong reason (not found) instead of payload-schema failure.

Suggested fix
-                "id": "gts.x.test6.events.type.v1~x.commerce.orders.order_placed.v1.0~x.y._.some_event2.v1.0",
+                "id": "gts.x.test6.events.type.v1~x.test6.invalid.event.v1.0~x.y._.some_event2.v1.0",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_op6_schema_validation.py` at line 191, The registered instance ID
string assigned to variable "id" in tests/test_op6_schema_validation.py is for
"...orders.order_placed..." but the invalid-instance validation later expects
the "...x.test6.invalid.event..." ID; update the "id" value used in the
registration to the exact instance ID that the test validates (i.e., the full
"...x.test6.invalid.event..." namespaced/versioned string) so the test exercises
payload-schema validation rather than a missing-instance error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/test_op6_schema_validation.py`:
- Line 191: The registered instance ID string assigned to variable "id" in
tests/test_op6_schema_validation.py is for "...orders.order_placed..." but the
invalid-instance validation later expects the "...x.test6.invalid.event..." ID;
update the "id" value used in the registration to the exact instance ID that the
test validates (i.e., the full "...x.test6.invalid.event..."
namespaced/versioned string) so the test exercises payload-schema validation
rather than a missing-instance error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0edaef5c-6369-4af7-912e-685d87011934

📥 Commits

Reviewing files that changed from the base of the PR and between 2cbb879 and 775d237.

📒 Files selected for processing (1)
  • tests/test_op6_schema_validation.py

@GeraBart GeraBart force-pushed the feat/anonymous_instances_test_OP#6 branch from 775d237 to 8918215 Compare March 5, 2026 05:46
Copy link
Copy Markdown

@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 (1)
tests/test_op6_schema_validation.py (1)

732-790: Consider extracting shared anonymous-flow setup into a helper.

Both anonymous test classes duplicate base/derived registration and instance scaffolding. A small builder/helper would reduce maintenance noise and keep intent-focused assertions in each class.

Also applies to: 806-858

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

In `@tests/test_op6_schema_validation.py` around lines 732 - 790, Extract the
duplicated anonymous-flow setup into a small helper used by both test classes:
create a function (e.g., build_anonymous_flow or register_anonymous_flow) that
takes the unique symbols _base_event_schema, _derived_event_schema,
ORDER_PLACED_PAYLOAD_SCHEMA and returns the sequence of Step/RunRequest
operations (register base, register derived, create anonymous instance, validate
instance). Replace the duplicated blocks in teststeps with a call to this helper
so tests keep only intent-focused assertions; ensure the helper exposes
parameters for instance id/tenantId if tests need variation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/test_op6_schema_validation.py`:
- Around line 836-837: The test "invalid-anonymous" uses a non-RFC4122 UUID
string ("8b2e3f45-6789-4abc-0123-bcdef1234567") for the JSON "id" and appears
also for "tenantId" in the same test; replace all three occurrences with
RFC4122-compliant UUIDs (e.g., change the problematic "0123" segment) so that
format validation passes and the test can properly exercise the
missing-required-field behavior in the invalid-anonymous test case.

---

Nitpick comments:
In `@tests/test_op6_schema_validation.py`:
- Around line 732-790: Extract the duplicated anonymous-flow setup into a small
helper used by both test classes: create a function (e.g., build_anonymous_flow
or register_anonymous_flow) that takes the unique symbols _base_event_schema,
_derived_event_schema, ORDER_PLACED_PAYLOAD_SCHEMA and returns the sequence of
Step/RunRequest operations (register base, register derived, create anonymous
instance, validate instance). Replace the duplicated blocks in teststeps with a
call to this helper so tests keep only intent-focused assertions; ensure the
helper exposes parameters for instance id/tenantId if tests need variation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1cf64e09-d166-41b9-a401-ff9967778c3a

📥 Commits

Reviewing files that changed from the base of the PR and between 775d237 and 8918215.

📒 Files selected for processing (1)
  • tests/test_op6_schema_validation.py

Comment thread tests/test_op6_schema_validation.py Outdated
GeraBart added 3 commits March 5, 2026 13:56
Signed-off-by: GeraBart <246844849+GeraBart@users.noreply.github.com>
Signed-off-by: GeraBart <246844849+GeraBart@users.noreply.github.com>
Signed-off-by: GeraBart <246844849+GeraBart@users.noreply.github.com>
@GeraBart GeraBart force-pushed the feat/anonymous_instances_test_OP#6 branch from 8918215 to 048994f Compare March 5, 2026 05:58
@GeraBart
Copy link
Copy Markdown
Contributor Author

GeraBart commented Mar 5, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
tests/test_op6_schema_validation.py (1)

732-790: Use instance-level copies of teststeps to avoid shared mutable state across test runs.

Class-level teststeps lists present a risk if HttpRunner or any test runner/plugin mutates the list during execution (via hooks, retries, or concurrent runs). While this framework executes steps sequentially by design, defensive copy prevents "modify-while-iterating" issues and shared state problems if execution frameworks change.

♻️ Recommended pattern
+from copy import deepcopy
...
 class TestCaseTestOp6ValidateInstance_AnonymousInstance(HttpRunner):
     config = Config(...).base_url(get_gts_base_url())
 
     def test_start(self):
         """Run the test steps."""
+        self.teststeps = deepcopy(self.__class__.teststeps)
         super().test_start()

 class TestCaseTestOp6ValidateInstance_AnonymousInstance_Invalid(HttpRunner):
     config = Config(...).base_url(get_gts_base_url())
 
     def test_start(self):
         """Run the test steps."""
+        self.teststeps = deepcopy(self.__class__.teststeps)
         super().test_start()

Also applies to: 806-858

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

In `@tests/test_op6_schema_validation.py` around lines 732 - 790, The shared
class-level list teststeps is mutable and can be mutated by runners; make tests
use instance-level copies by turning the static teststeps into a factory or by
copying it at test runtime—e.g., provide a function (get_teststeps or similar)
that returns a fresh list or call list(teststeps)/copy.deepcopy(teststeps)
before passing to the runner; update references around teststeps, RunRequest,
and Step in this file (and the other block at 806-858) to consume the
returned/copyed list so each test run gets an independent list.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/test_op6_schema_validation.py`:
- Around line 732-790: The shared class-level list teststeps is mutable and can
be mutated by runners; make tests use instance-level copies by turning the
static teststeps into a factory or by copying it at test runtime—e.g., provide a
function (get_teststeps or similar) that returns a fresh list or call
list(teststeps)/copy.deepcopy(teststeps) before passing to the runner; update
references around teststeps, RunRequest, and Step in this file (and the other
block at 806-858) to consume the returned/copyed list so each test run gets an
independent list.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9715c44e-81df-4eff-bb7e-181ad00ef2cb

📥 Commits

Reviewing files that changed from the base of the PR and between 8918215 and 048994f.

📒 Files selected for processing (1)
  • tests/test_op6_schema_validation.py

@GeraBart
Copy link
Copy Markdown
Contributor Author

GeraBart commented Mar 5, 2026

Re: deepcopy nitpick from the latest review —

Skipping this one. None of the other 12 test classes in this file use deepcopy, and HttpRunner does not mutate the teststeps list during execution. Adding it only to the anonymous test classes would be inconsistent, and adding it to all 14 would be over-engineering for a scenario that doesn't occur in practice.

@GeraBart GeraBart requested a review from Artifizer March 5, 2026 07:13
@Artifizer Artifizer merged commit 0872bdd into GlobalTypeSystem:main Mar 5, 2026
2 checks passed
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.

Add canonical OP#6 test for anonymous instance validation (UUID id + type field)

2 participants