Skip to content

feat(properties): resolve property search ids to their files - #453

Merged
M0Rf30 merged 2 commits into
openartifact:mainfrom
orcamedia:feat/property-search-artifacts
Nov 9, 2026
Merged

M0Rf30 merged 2 commits into
openartifact:mainfrom
orcamedia:feat/property-search-artifacts

Conversation

@orcamedia

Copy link
Copy Markdown
Contributor

Closes #444, in the shape agreed there.

GET /api/v1/repositories/{repo}/artifacts/search now answers with an additive artifacts list next to the unchanged artifact_ids:

{
  "artifact_ids": ["0b7e5c2a-3f1d-4c8e-9a6b-1d2e3f4a5b6c", "build-482"],
  "artifacts": [
    {"artifact_id": "0b7e5c2a-3f1d-4c8e-9a6b-1d2e3f4a5b6c", "name": "landing/v2/index.html", "version": "", "format": "raw"},
    {"artifact_id": "build-482"}
  ]
}

How ids are resolved

In the search query itself (SearchByProperty in internal/database/queries/properties.sql): one LEFT JOIN of package_files → package_versions → packages on the search result, no lookup per id and no package listing.

  • An id resolves when it is the id of a live file of the same repository (package_files.id, what the web UI stores via primaryFile(entry).id).
  • Only text shaped like a UUID is cast (CASE WHEN … ~* uuid-pattern THEN ::uuid END), so external ids never reach the cast and the join stays on the primary key.
  • Files of another repository, deleted files (deleted_at on the file or its version) and anything else stay {"artifact_id": …}. HTTP paths are not matched, as agreed.

Also in this PR

  • oa props search: new NAME column. I kept --format json as the plain list of ids so scripts that read it keep working. Happy to switch it to the artifacts objects if you prefer.
  • OpenAPI: PropertySearchResult and PropertySearchArtifact schemas on the 200 response; regenerated web client (bun run generate-api), reference docs and openapi.json.gz (make docs-gen).
  • docs/repositories/properties.md: a "Search results" section, and the Model paragraph now says the web UI uses the id of the version's first file rather than the package id (from your correction on Property search: say which artifact each returned id is #444).
  • PropertyStore.SearchByProperty returns []models.PropertyMatch; the four test doubles follow.

Tests

  • internal/database/property_search_integration_test.go (integration, Postgres): a file id of the repository resolves to name, empty version and raw; unresolved and still listed are an external id (build-482), a file id of another repository, an upper-case UUID that names no file, and a deleted file; the same tag in the other repository doesn't leak in; results are sorted and distinct. I checked it fails when the same-repository condition is removed from the join.
  • internal/api/properties_search_test.go: answer shape, fields omitted for unresolved ids, empty lists rather than null.
  • internal/oacli/contract_test.go: the NAME column; the existing ids-only case still passes (older servers).

Checked locally on current main (macOS, Postgres 18): make check, cmd/docgen -check, sqlc diff, bun run typecheck, the unit suite with -race and the slim (noai,nomcp) suite pass. go test -tags integration ./internal/database/ passes except TestVulnScanOverviewUsesIndexes, which fails the same way on main here (out of shared memory while seeding scan_jobs, also with --shm-size=1g), so it looks specific to Docker on my Mac rather than this change.

🤖 Generated with Claude Code

GET /api/v1/repositories/{repo}/artifacts/search answered only
{"artifact_ids": [...]}, so a client had to list the repository's packages
to tell what matched. It now also returns "artifacts": the same ids, each
with the name, version and format of the package version it names when the
id is the id of a live file of the same repository (package_files.id, the
listing item id the web UI and oa store properties under). Other ids keep
only artifact_id. artifact_ids is unchanged.

The ids are resolved in the search query itself, with one LEFT JOIN of
package_files, package_versions and packages. Only text shaped like a UUID
is cast, so external ids never reach the cast and the lookup stays on the
primary key. Files of other repositories and deleted files do not resolve.

oa props search gains a NAME column; its JSON output stays the list of ids.
OpenAPI, the generated web client and reference docs, and
docs/repositories/properties.md are updated.

Closes openartifact#444

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

Thanks, the SQL and the response shape look right (UUID guard, same-repository join, deleted file and version left unresolved, empty lists not null, artifact_ids unchanged). One change before merging:

  • PropertyMatch.Resolved() (internal/database/models/property.go:20) is only called from property_search_integration_test.go. AGENTS.md: code only tests call doesn't go in a production file. Either inline m.Name != nil in the test and drop the method, or use it in PropertyStore.SearchByProperty / the handler.

Minor, no change needed: the text table of oa props search gains a NAME column, so anyone parsing it line by line sees a change; worth a line in the upgrade notes.

Only the integration test called it; it now checks Name directly. Add an
upgrade note for the NAME column of oa props search and the new
artifacts field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@orcamedia

Copy link
Copy Markdown
Contributor Author

Thanks! Done: PropertyMatch.Resolved is gone and the test checks m.Name directly. I also added an "Unreleased" entry to upgrading.md for the NAME column of oa props search and the new artifacts field. #454 adds an entry to the same section, so whichever merges second will need a small rebase, which I'll handle.

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

Thanks, all addressed.

@M0Rf30
M0Rf30 merged commit 6323e66 into openartifact:main Nov 9, 2026
23 checks passed
@orcamedia
orcamedia deleted the feat/property-search-artifacts branch November 9, 2026 18:26
@M0Rf30 M0Rf30 mentioned this pull request Nov 9, 2026
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.

Property search: say which artifact each returned id is

2 participants