Skip to content

Preserve custom targets in Ossie export - #116

Closed
s4chinjha wants to merge 1 commit into
hydra-db:mainfrom
s4chinjha:fix/ossie-export-target-concepts
Closed

s4chinjha wants to merge 1 commit into
hydra-db:mainfrom
s4chinjha:fix/ossie-export-target-concepts

Conversation

@s4chinjha

@s4chinjha s4chinjha commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

to_ossie() and toOssie() emitted relationship roles for custom target concepts that were not present in the ontology document. This draft registers undeclared custom targets while keeping the synthetic Any target as a role-only placeholder.

Ossie 0.3.0.dev0 has no OneToMany multiplicity value. The exporters now use the existing left-out warning path when that constraint cannot be represented instead of emitting an unsupported value.

The change includes mirrored Python and TypeScript regression tests.

Linked issue

Closes #105

AI Assistance

Model Effort
GitHub Copilot Medium

Checklist

  • Implements an issue a maintainer has /approved.
  • Small and scoped to that issue.
  • Breaking changes described below, or none.

Breaking changes

None.

Validation

  • SELFGRAPH_TEST_STORE=kuzu python -m pytest tests/test_trust.py -q (27 passed)
  • npm test -- --run test/trust.test.ts (24 passed)
  • npm run typecheck
  • npm run lint
  • ruff check and ruff format --check on changed Python files

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@github-actions

Copy link
Copy Markdown

This is PR 3 of 3 you may keep open at a time.

@s4chinjha
s4chinjha marked this pull request as ready for review November 15, 2026 20:49
@github-actions

Copy link
Copy Markdown

This is PR 3 of 3 you may keep open at a time.

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Biome format fails on trust.test.ts:437 (CI red). Please run npm run format, update the stale docstring at _export.py:49, and the Ossie table in docs/schema.md.

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check this

Comment thread src/selfgraph/_export.py Outdated
placeholder = f"{target}:other"
concepts.setdefault(source, {"concept": source, "type": "EntityType", "relationships": []})
if target != "Any":
concepts.setdefault(target, {"concept": target, "type": "EntityType", "relationships": []})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Main now rejects undeclared relation targets, so the new tests fail once merged (unknown type Company), and this branch now only adds alias or case variants like Org next to Company. Please rebase and resolve targets to their declared type. Also add a to_ossie case to the conformance pair.

Comment thread typescript/src/export.ts Outdated
placeholder = `${target}:other`;
}
if (!concepts.has(source)) concepts.set(source, { concept: source, type: "EntityType", relationships: [] });
if (target !== "Any" && !concepts.has(target)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here, and the toOssie docstring still needs the update the Python one got.

@s4chinjha
s4chinjha force-pushed the fix/ossie-export-target-concepts branch from 287eabe to 0bb71c2 Compare November 16, 2026 12:43

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check this

Comment thread src/selfgraph/_export.py Outdated
multiplicity = {"multiplicity": "OneToOne" if relation.to.max_count == 1 else "ManyToOne"}
for source in relation.from_.types:
for raw_source in relation.from_.types:
source = canonical_entity_type(raw_source, schema)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Endpoints are canonicalized but not deduplicated, so Person and User sources with Company and Org targets export four identical WORKS_AT_Company relationships under Person. Main gives distinct ones. Please dedupe sources and targets after resolving them.

Comment thread src/selfgraph/_export.py Outdated
placeholder = f"{target}:other"
concepts.setdefault(source, {"concept": source, "type": "EntityType", "relationships": []})
if target != "Any":
concepts.setdefault(target, {"concept": target, "type": "EntityType", "relationships": []})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Every target is a declared type now, so this never adds anything. Removing it leaves the output byte identical. Please drop it.

Comment thread typescript/src/export.ts Outdated
placeholder = `${target}:other`;
}
if (!concepts.has(source)) concepts.set(source, { concept: source, type: "EntityType", relationships: [] });
if (target !== "Any" && !concepts.has(target)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same two points here.

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check this

Comment thread src/selfgraph/_export.py Outdated
words = rtype.lower().replace("_", " ")
targets = relation.to.types or ["Any"]
raw_targets = relation.to.types or ["Any"]
targets = list(dict.fromkeys(t if t == "Any" else canonical_entity_type(t, schema) for t in raw_targets))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The Any check runs before canonicalizing, so a type alias spelled Any for Company exports the wildcard instead of Company. Please canonicalize first and treat Any only when it is not a declared alias.

Comment thread typescript/src/export.ts Outdated
const words = rtype.toLowerCase().replaceAll("_", " ");
const targets = relation.to.types.length ? relation.to.types : ["Any"];
const rawTargets = relation.to.types.length ? relation.to.types : ["Any"];
const targets = [...new Set(rawTargets.map((t) => (t === "Any" ? "Any" : canonicalEntityType(t, schema))))];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here.

return "\n".join(lines)


def ossie_export():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This repeats the log capture block from neo4j_export_warnings line for line. Please share one helper.

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check this

Comment thread src/selfgraph/_export.py Outdated
)
words = rtype.lower().replace("_", " ")
targets = relation.to.types or ["Any"]
raw_targets = relation.to.types or ["Any"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The Any alias case is fixed, but now a relation with no target types exports whichever entity has the alias Any instead of the wildcard. Please canonicalize only the listed targets and fall back to Any when the list is empty.

Comment thread typescript/src/export.ts Outdated
});
const words = rtype.toLowerCase().replaceAll("_", " ");
const targets = relation.to.types.length ? relation.to.types : ["Any"];
const rawTargets = relation.to.types.length ? relation.to.types : ["Any"];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here.

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check this

Comment thread tests/test_trust.py Outdated
assert doc["ontology"][0]["relationships"][0]["roles"] == [{"concept": "Company"}]


def test_ossie_export_keeps_the_any_wildcard_for_relations_without_targets():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test passes on main, so it does not cover the change. Please remove it.

Comment thread typescript/test/trust.test.ts Outdated
expect(result.ontology[0]!.relationships![0]!.roles).toEqual([{ concept: "Company" }]);
});

it("keeps the Any wildcard for relations without targets", () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here: passes on main. Please remove it.

Comment thread typescript/test/conformance/ts_side.ts Outdated
*/
export function ossieExport(): { doc: unknown; warnings: string } {
const lines: string[] = [];
const previous = setLogger((message) => lines.push(message));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This repeats the setLogger capture block from neo4jExportWarnings. Please share one helper, like the Python side now does.

@s4chinjha

Copy link
Copy Markdown
Contributor Author

@arrry-hydraDB check this one too

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check this

Comment thread src/selfgraph/_export.py Outdated
words = rtype.lower().replace("_", " ")
targets = relation.to.types or ["Any"]
targets = (
list(dict.fromkeys(canonical_entity_type(t, schema) for t in relation.to.types))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#215 now canonicalizes and dedupes endpoint types when the schema is parsed, so this does nothing new: the Ossie output matches main on 30 seeded schemas. Please drop it and keep only the OneToMany warning.

Comment thread typescript/src/export.ts Outdated
const words = rtype.toLowerCase().replaceAll("_", " ");
const targets = relation.to.types.length ? relation.to.types : ["Any"];
const targets = relation.to.types.length
? [...new Set(relation.to.types.map((t) => canonicalEntityType(t, schema)))]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here.

Comment thread tests/test_trust.py Outdated
]


def test_ossie_export_dedupes_canonicalized_endpoints():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This and the Any alias test at line 371 pass on main after #215. Please remove them.

Comment thread typescript/test/trust.test.ts Outdated
]);
});

it("treats a declared Any alias as its entity type", () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same: this and the dedupe test at line 491 pass on main.

@s4chinjha
s4chinjha force-pushed the fix/ossie-export-target-concepts branch from 933fec0 to 136fcfb Compare November 17, 2026 18:17

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check this


@return (dict): the Ossie document and the logged warning lines joined by newlines.
"""
doc, warnings = captured_logs(lambda: Schema.model_validate(OSSIE_SPEC).to_ossie())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Both sides leave the warning out on main, so this pair passes on main and nothing in the PR catches the bug. Please make OSSIE_SPEC include a OneToMany relation and assert the OneToMany warning, and keep one unit test per SDK for it (the ones in test_trust.py and trust.test.ts were removed).

* @return ({ doc: unknown; warnings: string }): the Ossie document and the logged warning lines joined by newlines.
*/
export function ossieExport(): { doc: unknown; warnings: string } {
const { result, logs } = capturedLogs(() => toJsonable(toOssie(Schema.parse(OSSIE_SPEC))));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here.

@0xNexuz

0xNexuz commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

@s4chinjha for Arrry's last review (a OneToMany case in the conformance pair, plus one unit test per SDK), I put it on top of your branch as one commit: 0xNexuz@b1f7efd

  • adds LEADS (Person to Company, to.max_count: 1) to OSSIE_SPEC on both sides and asserts the OneToMany line in the schema conformance test
  • adds test_ossie_export_leaves_out_and_logs_a_one_to_many_multiplicity and its trust.test.ts twin

All three fail with your _export.py / export.ts change reverted and pass with it. ruff, Biome and tsc are clean.

git fetch https://github.com/0xNexuz/selfgraph suggest/pr116
git cherry-pick b1f7efd
git push

@arrry-hydraDB

Copy link
Copy Markdown
Collaborator

I'm closing this one. @0xNexuz added the OneToMany conformance case and the unit tests my last review asked for in b1f7efd, so I'll take the fix from a fresh PR with that commit on top of your changes. Thanks for the work on #105.

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.

to_ossie drops target concepts not declared in schema.entities and ignores OneToMany multiplicity

3 participants