Skip to content

Add squash and collection commands#18

Open
HuiJun wants to merge 2 commits into
developfrom
feature/squash-collections
Open

Add squash and collection commands#18
HuiJun wants to merge 2 commits into
developfrom
feature/squash-collections

Conversation

@HuiJun

@HuiJun HuiJun commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends the CLI toward feature parity with layer1-service by adding two
recently-added server capabilities:

  • squash — squash the linear commit path between two locks into a
    single diff on the newer lock's commit (POST /orgs/{org}/repos/{repo}/squash).
  • collection — manage Collections, layer1's lightweight groupings
    of refs (branches/locks/scratches) that can be read and queried as a
    union graph (/orgs/{org}/collections).

Commands

squash

flexo squash
<dstLock> must be the newer commit. Accepts lock names (resolved to
lock IRIs under the current org/repo) or full IRIs. Prints the resulting
squashed commit id.

collection

flexo collection list
flexo collection get
flexo collection create --ref --ref ...
flexo collection query (-q | -i ) -o

  • create takes one or more --ref values; each is resolved to a branch
    IRI under the current org/repo (or passed through if already a full IRI).
  • query runs SPARQL across the union of the collection's collected ref
    graphs; reads the query from -q/--query or -i/--input, writes
    results to -o/--output or stdout.

Implementation

  • FlexoMmsClient: squash, listCollections, getCollection,
    createCollection, getCollectionModel, queryCollection, plus RDF
    parsing of collections (parseCollectionsFromRdf).
  • New Collection model POJO (id, name, etag, collectedRefs).
  • New SquashCommand and CollectionCommand (with list/get/create/
    query subcommands), registered in FlexoCLI + help listing.
  • Ref resolution against server root context: refs are resolved
    against the server's configured root context (e.g. http://layer1-service),
    not the client base URL, since layer1 stores and validates refs under
    that root. getServerRootContext() derives it from an existing branch's
    commit IRI; absolute http(s) IRIs pass through unchanged.

Follows existing command/client patterns (BaseCommand, createClient,
ConsoleUtil, Turtle bodies, extractCommitId).

Testing

  • ./gradlew clean test — green.
  • New FlexoMmsClient tests: squash success/error, collection
    list/get/create (incl. empty-refs guard)/query success/error, and
    ref-resolution (server root context + absolute passthrough).
  • Constructor smoke tests for both commands (matches existing command
    test style).
  • Verified live against a locally-built layer1-service image (collections
    feature): collection create --ref master --ref feature-a resolves to
    http://layer1-service/... IRIs and creates; list/get round-trip;
    query returns the correct union count. squash reaches the server with
    the correct path/body (verified via the server's precise
    "lock does not exist" response).

Notes / limitations

  • squash end-to-end is not exercised here because the CLI has no lock
    command yet (can't create the two locks squash operates on). The squash
    client method is unit-tested and the request path/body are verified
    against the live server.
  • collection query returns HTTP 500 when two collected refs point to
    the same commit — a server-side union-graph construction issue
    (duplicate FROM/FROM NAMED), not a CLI bug; the CLI sends a valid query.
  • Requires a layer1-service build that includes the collections feature.

HuiJun added 2 commits July 9, 2026 21:53
Add two new git-style/layer1 commands to reach closer feature parity
with the flexo-mms-layer1-service recent endpoints:

- squash <srcLock> <dstLock>: POST /orgs/{org}/repos/{repo}/squash,
  squashing the linear commit path between two locks into a single diff.
- collection {list|get|create|query}: org-level collections
  (/orgs/{org}/collections), lightweight groupings of refs queryable
  as a union graph.

FlexoMmsClient gains squash, listCollections, getCollection,
createCollection, getCollectionModel and queryCollection methods plus a
Collection model POJO and RDF parsing helper, all matching existing
client/command conventions.

Adds 8 client tests and 2 command smoke tests (308 tests total).
Collection create (--ref names) and squash (lock names) resolved ref
IRIs against the client base URL, but layer1-service stores and
validates refs under its configured root context (e.g.
http://layer1-service), causing HTTP 404 'Ref does not exist'.

Add FlexoMmsClient.getServerRootContext() which derives the server
root from an existing branch commit IRI, and route resolveBranchIri()
and resolveLockIri() through it. Absolute http(s) IRIs pass through
unchanged. Simplify CollectionCommand.CreateCommand to use
resolveBranchIri(). Add tests.
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.

1 participant