feat(ingest/repository-documents): import OKF bundles by the OKF 0.3 rules

SH
2h ago
+1878-154

Brings the GitHub and GitLab documents OKF import (repository_documents) up to OKF 0.3. It reads input leniently: OKF 0.2 bundles keep importing, and the stricter 0.3 rules for stale_after and verified apply to every bundle, whatever its version.

Changes, by OKF 0.3 rule

  • Date-only timestamps (§5, §13.2). stale_after, generated.at and verified[].at accept 2026-06-30, read as the start of that day in UTC. A date-time with no offset is still invalid. Date-times are now checked against RFC 3339 before parsing, so other ISO 8601 forms (20260630T100000Z, week dates, T10Z) are rejected, and every supported Python version gives the same result.
  • An unreadable stale_after must never count as fresh (§5.5, §11.2). New optional okfProperties.staleAfterInvalid: boolean, searchable as okfStaleAfterInvalid and exposed in GraphQL as OkfProperties.staleAfterInvalid: Boolean! (false when unset). staleAfter stays null.
    • Why a flag and not the raw string: the raw value is already stored once, in raw (and GraphQL frontmatter), so storing it again would duplicate it. Consumers need a yes/no "treat as stale" signal that search can filter on, and a boolean gives that. A sentinel date would put a fake date in the okfStaleAfter range queries.
  • verified events need both by and at (§5.2). An event missing either one, or with an unreadable at, is dropped with an "Incomplete OKF verification event" warning (okf_incomplete_verified_events). It stays in raw. generated without at is still kept.
  • okf_version is optional (§2, §8.1). Any index.md with frontmatter defines a bundle. An unversioned index.md inside an existing bundle is a folder listing, not a nested bundle, so a bundle where every folder index.md has frontmatter keeps its concept IDs. A versioned index.md still starts a nested bundle, as before. okf_bundle_roots works as before.
  • Unquoted okf_version: 0.3. It is kept as written ("0.3", and 0.10 stays "0.10") rather than dropped. A boolean still warns.
  • Empty values count as absent (§11.2). null, "" and [] produce no warnings for any typed key, reference key or list entry, type included.
  • Dot-paths are not part of a bundle (§3.2). Files and folders whose names start with . below a bundle root (e.g. .github/) are not imported (okf_dot_paths_excluded). An index.md in such a dot-folder does not start a nested bundle, even with okf_version. Files outside bundles are unchanged, and a configured root may itself be a dot-folder.
  • x- extension keys (§4.1). x-datahub-owners, x-datahub-glossary_terms and x-datahub-id are aliases of the unprefixed keys. The unprefixed keys are still accepted, and the prefix is never required. If a file sets both forms, the unprefixed key wins, because it is the documented, always-accepted form. The run warns ("Conflicting OKF alias keys", okf_conflicting_alias_keys). Attribution keeps the logical key (owners), so switching between the two forms does not churn associations.
  • Bundle metadata (§8.1, §13.3). The bundle-root index.md's title, description and license are stored on OkfBundle (and GraphQL OkfBundle), so every concept carries its bundle's name, scope and license. Documents have no description field, so this is where a bundle's description is kept. Values are trimmed (the same rule #21884 uses for the bundle title), empty values are absent, and a non-string value warns. Explicit okf_bundle_roots read their index.md metadata too.
  • Docs. github-documents_post.md now describes OKF 0.3 and links the spec's new home. docs/how/breaking-changes.md describes the behaviour changes.

MAPPING_VERSION goes from 6 to 7, so the next run re-maps existing concepts once and they pick up the new typed values.

Model

  • OkfProperties gains an optional staleAfterInvalid field with @Searchable BOOLEAN.
  • OkfBundle gains optional title, description and license. They are not searchable.
  • okfProperties goes from schemaVersion 2 to 3 so consumers can tell which aspects carry the 0.3 fields. bump_schema_versions.py would treat these additive optional fields as needing no bump, so this one is deliberate.
  • SearchTemplateGoldenTest and the V3 search field tests pass unchanged: no new field is queried by default.

Why this lives in repository_documents

The OKF reading code is shared by github-documents and gitlab-documents, and no other source reads OKF. Nothing here belongs in the framework.

Coordination

  • Touches source.py next to #21146 (lifecycle stage on import). The only change there is a small block after bundle discovery, so a conflict would be trivial.
  • Overlap with #21884 (hierarchy).
    • #21884 names a bundle's top document from the root index.md title, using the same rule as OkfBundle.title here (a non-empty string, trimmed). The two stay consistent, and #21884 can read bundle.title once both land.
    • Both PRs handle dot-paths. #21884 makes enclosing_bundle return None for a dot-path, which turns such a file into a plain document. This PR leaves enclosing_bundle unchanged and drops dot-paths from the import in okf_bundles.is_excluded_from_bundle, which relies on enclosing_bundle still returning the bundle. Whichever PR merges second has to reconcile this: keep a single check, and keep is_excluded_from_bundle working on the raw enclosing root.
  • Version-aware path resolution (§6.2, §12.1) is out of scope; this PR does not touch path code.

Tests

  • Unit tests for each rule: test_okf_metadata.py (date-only, staleAfterInvalid, incomplete verified, empty values), test_okf_mapping.py (aliases and precedence), test_okf_bundles.py (unversioned bundles, nested folder indexes, numeric okf_version, dot-paths), test_okf_frontmatter.py (empty type). On master's source, 30 of these fail.

  • Golden: the integration test now runs on two bundles. The existing OKF 0.2 fixture is kept; its golden changes only mappingVersion and the source hashes. A new OKF 0.3 fixture (fixtures_okf_0_3/) covers an unquoted okf_version, date-only values, an unreadable stale_after, an incomplete verified event, x-datahub- keys, empty values and a .github/ folder. Its fixture dir is added to .prettierignore like the existing one.

  • DocumentMapperTest covers staleAfterInvalid in GraphQL.

  • PR title follows the Contributing Guideline

  • Tests added/updated

  • Docs updated

  • Breaking changes documented in docs/how/breaking-changes.md


🤖 Opened with cclaude on behalf of @shirshanka