diff --git a/README.md b/README.md index dcaad57..fa4630f 100644 --- a/README.md +++ b/README.md @@ -85,13 +85,14 @@ A channel can hold an index of its packages at `/orbit-index:latest The manifest has `artifactType` `application/vnd.latha.orbit.index.v1` and one JSON layer (`application/vnd.latha.orbit.index.v1+json`): ```json -{"packages":[{"name":"mytool","version":"1.4.0","description":"...","versions":["1.4.0"]}]} +{"packages":[{"name":"mytool","version":"1.4.0","description":"...","versions":["1.4.0"],"digest":"sha256:..."}]} ``` - `orbit publish` adds the package to the index, and creates the index from the catalog if there is none. `--no-index` skips this. - `orbit index [--channel ]` rebuilds it from the catalog. Use it after deleting a package, or if two publishes ran at once and one entry was lost. On a registry without a catalog, name the packages: `orbit index mytool othertool`. +- `digest` is the manifest digest of `version`. Indexes built before it was added lack it; `orbit index` adds it. - Installs and version lookups never read the index, so a stale one can't change what is installed. -- Search keeps a copy of each channel's list in `~/.orbit/cache/indexes/` and uses it for an hour without touching the network. After that it fetches the list again, or uses the old copy with a warning if the registry can't be reached. `orbit search --refresh` fetches now. Your own `publish`, `index`, `login` and `logout` drop the copies they affect. A channel without an index is cached too, if it has at most 100 repositories. +- Search and `orbit info` keep a copy of each channel's list in `~/.orbit/cache/indexes/` and use it for an hour without touching the network. After that it fetches the list again, or uses the old copy with a warning if the registry can't be reached. `orbit search --refresh` fetches now. Your own `publish`, `index`, `login` and `logout` drop the copies they affect. A channel without an index is cached too, if it has at most 100 repositories. - The index is built with the publisher's login. On a registry where packages in one namespace can be private while others are public, a public index reveals the private names, descriptions and versions. Gitea sets visibility per owner, so this doesn't apply there. ## Usage @@ -277,7 +278,7 @@ src/main/ model.mbt orbit.json / state.json / config.json (+ tests) registry.mbt OCI registry ops: tags, resolve, cached manifests, fetch, publish, login index.mbt channel index: build, publish, read (+ tests) - index_cache.mbt local copies of channel listings for search (+ tests) + index_cache.mbt local copies of channel listings for search and info (+ tests) details.mbt package details shown by install and info (+ tests) solver.mbt lazy Resolvo-style CDCL SAT solver & UNSAT explainer (+ tests) ops.mbt SAT-backed global install/upgrade, remove/rollback/gc/search @@ -307,5 +308,5 @@ Fixes needed for current MoonBit, kept here in case you build with an older comp - There's no lock file for concurrent runs, and no install hooks, by design. - `orbit gc` only preserves global current and rollback builds (run `orbit install` / `orbit sync` in a project to re-populate missing store entries from its `orbit.lock`). -- `orbit info ` reads installed package details (the project's, then the global ones) without contacting the registry. Use `orbit versions ` to check published versions. +- `orbit info ` reads installed package details (the project's, then the global ones) without contacting the registry. A package that isn't installed, or `orbit info [channel::]@` for another build, is looked up in the same cached channel listings as `orbit search`: it shows the newest version's description, documentation link, digest, bins, dependencies and conflicts. With the digest from the index and the config blob in the manifest cache, a repeated `info` needs no network; another version, or an index without digests, is resolved in the registry. Use `orbit versions ` to list published versions. - `search` needs a channel index or the registry's catalog API (Gitea has it, also without a login). Otherwise use `orbit versions `. diff --git a/planning/k7q3m-show-info-for-uninstalled-packages.md b/planning/k7q3m-show-info-for-uninstalled-packages.md new file mode 100644 index 0000000..9a57cbc --- /dev/null +++ b/planning/k7q3m-show-info-for-uninstalled-packages.md @@ -0,0 +1,11 @@ +--- +data: + priority: normal + status: done + type: feature +id: k7q3m +title: Show info for packages that aren't installed +--- +`orbit info ` only worked for installed packages. It should also describe a package that is in a channel. + +Outcome: when the package isn't installed (or `channel::` / `@constraint` asks for a build other than the installed one), `orbit info` finds the package in the same cached channel listings as `orbit search` (`channel_listing`). Index entries now record the `digest` of their version's manifest, so with the config blob in the digest-keyed manifest cache a repeated `info` takes ~8 ms with no network; another version, or an index built before digests, falls back to resolving in the registry. It and prints its description, documentation link, channel, digest, packaged bins, dependencies and conflicts. In a project it still prefers the locked package. `available_details` in `src/main/details.mbt`. diff --git a/src/main/details.mbt b/src/main/details.mbt index 35c1285..66b42fd 100644 --- a/src/main/details.mbt +++ b/src/main/details.mbt @@ -61,6 +61,36 @@ fn package_details( ] } +///| +/// The details of a build in a channel that isn't installed: it has no paths +/// yet, so bins are shown as they sit in the package. +fn available_details( + m : Manifest, + channel~ : String, + digest~ : String, +) -> Array[Detail] { + let bins = m.bins.copy() + if bins.is_empty() { + bins.push("(none)") + } + let specs = fn(reqs : Map[String, String]) { + let out : Array[String] = [] + for n, c in reqs { + out.push(n + "@" + c) + } + join(out, " ") + } + [ + ("description", [m.description]), + ("docs", [m.documentation]), + ("channel", [channel]), + ("digest", [digest]), + ("bin", bins), + ("depends", [specs(m.depends)]), + ("conflicts", [specs(m.conflicts)]), + ] +} + ///| fn installed_details(ctx : Ctx, p : Installed) -> Array[Detail] { package_details( @@ -116,3 +146,17 @@ test "package details show paths and every bin" { "bin: (none)", ]) } + +///| +test "available details show bins as packaged and the docs link" { + let m = parse_manifest( + "{\"name\":\"t\",\"version\":\"1.0.0\",\"description\":\"A tool\",\"documentation\":\"https://x/t\",\"bin\":[\"bin/a\"],\"depends\":{\"x\":\"^1\"}}", + ) + assert_eq( + detail_lines(available_details(m, channel="main", digest="sha256:ab"), ""), + [ + "description: A tool", "docs: https://x/t", "channel: main", "digest: sha256:ab", + "bin: bin/a", "depends: x@^1", + ], + ) +} diff --git a/src/main/index.mbt b/src/main/index.mbt index 40ae6bf..acf258c 100644 --- a/src/main/index.mbt +++ b/src/main/index.mbt @@ -20,6 +20,7 @@ struct IndexEntry { version : String description : String versions : Array[String] // newest first + digest : String // of the `version` manifest; "" in older indexes } ///| @@ -33,6 +34,9 @@ fn index_object(entries : Array[IndexEntry]) -> Map[String, Json] { o["version"] = Json::string(e.version) o["description"] = Json::string(e.description) o["versions"] = strs_json(e.versions) + if e.digest != "" { + o["digest"] = Json::string(e.digest) + } pkgs.push(Json::object(o)) } let top : Map[String, Json] = Map([]) @@ -64,6 +68,7 @@ fn parse_index(text : String) -> Array[IndexEntry] raise OrbitError { version: jstr(o, "version", ""), description: jstr(o, "description", ""), versions: jstrs(o, "versions"), + digest: jstr(o, "digest", ""), }) } } @@ -186,13 +191,15 @@ async fn read_index_entry( return None } let tag = if tags.contains("latest") { "latest" } else { tags[0] } - match orbit_info(fetch_raw_manifest(ch, name, tag)) { + let raw = fetch_raw_manifest_bytes(ch, name, tag) + match orbit_info(utf8_decode(raw)) { Some(info) => Some(IndexEntry::{ name, version: info.version, description: info.description, versions: sorted_versions(tags), + digest: sha256_digest(raw), }) None => None } @@ -334,7 +341,13 @@ async fn index_published(ch : Channel, name : String) -> Unit noraise { ///| test "index round-trips, sorted, without unusable names" { let entry = fn(name : String) { - IndexEntry::{ name, version: "1.0.0", description: "d", versions: ["1.0.0"] } + IndexEntry::{ + name, + version: "1.0.0", + description: "d", + versions: ["1.0.0"], + digest: "sha256:ab", + } } let parsed = parse_index( index_json([ @@ -346,6 +359,12 @@ test "index round-trips, sorted, without unusable names" { ) assert_eq(parsed.map(fn(e) { e.name }), ["a", "zed"]) assert_eq(parsed[0].versions, ["1.0.0"]) + assert_eq(parsed[0].digest, "sha256:ab") + // Indexes written before digests were recorded still parse. + let old = parse_index( + "{\"packages\":[{\"name\":\"a\",\"version\":\"1.0.0\",\"description\":\"d\",\"versions\":[\"1.0.0\"]}]}", + ) + assert_eq(old[0].digest, "") // Only an index artifact is used, and it is not an Orbit package. assert_true(index_layer_digest("{\"artifactType\":\"x\"}") is None) assert_true( diff --git a/src/main/index_cache.mbt b/src/main/index_cache.mbt index 9480827..4d46a63 100644 --- a/src/main/index_cache.mbt +++ b/src/main/index_cache.mbt @@ -1,5 +1,5 @@ -// Local copies of channel listings, so that a repeated search needs no network. -// Installs and version lookups never read them. +// Local copies of channel listings, so that a repeated search or info needs no +// network. Installs and version lookups never read them. ///| /// How long a copy is used before it is fetched again. @@ -91,7 +91,8 @@ async fn drop_cached_indexes(root : String) -> Unit noraise { } ///| -/// A channel's packages for search, which still has to match `term`: a fresh +/// A channel's packages for search and info, which still have to match `term` +/// (a large channel without an index only lists those that do): a fresh /// copy, else its index, else the registry's catalog. If the registry fails, an /// old copy is used. None means the channel couldn't be listed. async fn channel_listing( @@ -177,6 +178,7 @@ async fn list_catalog( version: info.version, description: info.description, versions: [], + digest: "", }) None => () } diff --git a/src/main/main.mbt b/src/main/main.mbt index d03677a..fedf12d 100644 --- a/src/main/main.mbt +++ b/src/main/main.mbt @@ -41,8 +41,9 @@ let usage : String = #| orbit upgrade [-g] [name...] jointly upgrade within constraints #| orbit rollback switch to the previous global build #| orbit list [-g] installed global packages - #| orbit info [-g] [channel::] details of an installed package: paths, - #| bins, dependencies (local only) + #| orbit info [-g] [channel::][@constraint] + #| details of an installed package, else of + #| the newest matching build in a channel #| orbit versions published versions #| orbit search [--refresh] [term] list packages (cached for an hour) #| orbit gc delete unused builds from the store @@ -349,7 +350,7 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError { None => cmd_list(load_ctx()) } "info" => { - need(pos, 1, "info [channel::]") + need(pos, 1, "info [channel::][@constraint]") match resolve_project_or_none(force_global, manifest_path) { Some(mf) => cmd_project_info(load_ctx(), mf, pos[0]) None => cmd_info(load_ctx(), pos[0]) diff --git a/src/main/ops.mbt b/src/main/ops.mbt index a1478fa..301960d 100644 --- a/src/main/ops.mbt +++ b/src/main/ops.mbt @@ -764,25 +764,94 @@ async fn locate_spec( } ///| -fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError { - let (pin, name) = split_channel(spec) - let p = match ctx.state.get(name) { - Some(p) => p - None => raise OrbitError("\{spec} is not installed") +/// Find a build for info in the channel listings that search caches: the +/// pinned channel, else the one it is installed from, else by priority. None +/// if no listing has a matching version with a known digest, so the registry +/// has to be asked. +async fn listed_build( + ctx : Ctx, + name : String, + pin : String?, + constraint : String, +) -> (Channel, String, String)? raise OrbitError { + let wanted = match pin { + Some(c) => Some(c) + None => ctx.state.get(name).map(i => i.channel) } - if pin is Some(channel) && channel != p.channel { - raise OrbitError("\{spec} is not installed (installed from '\{p.channel}')") + let channels = match wanted { + Some(c) => [find_channel(ctx, c)] + None => ctx.channels } - println("\{name} \{p.version} (installed)") - print_details(installed_details(ctx, p), " ") - print_details( - [ - ("constraint", [p.constraint]), - ("needed by", [join(reverse_deps(ctx, name), " ")]), - ("rollback", [join(p.history.map(g => g.version), " ")]), - ], - " ", - ) + for ch in channels { + let entries = match channel_listing(ctx.root, ch, name, false) { + Some(es) => es + None => continue + } + match find_entry(entries, name) { + Some(e) => + if e.digest != "" && satisfies_all(e.version, [constraint]) { + return Some((ch, e.version, e.digest)) + } else { + // Another version, or no digest: the registry knows its digest. + return None + } + None => () + } + } + None +} + +///| +/// Details of an installed package, or of the newest matching build in a +/// channel when it isn't installed (or `channel::` / `@constraint` asks for +/// another build). +async fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError { + let (pin, name, constraint, explicit) = parse_spec_full(spec) + match ctx.state.get(name) { + Some(p) => + if (pin is None || pin == Some(p.channel)) && + (!explicit || satisfies_all(p.version, [constraint])) { + println("\{name} \{p.version} (installed)") + print_details(installed_details(ctx, p), " ") + print_details( + [ + ("constraint", [p.constraint]), + ("needed by", [join(reverse_deps(ctx, name), " ")]), + ("rollback", [join(p.history.map(g => g.version), " ")]), + ], + " ", + ) + return + } + None => () + } + let (ch, version, digest) = match listed_build(ctx, name, pin, constraint) { + Some(found) => found + None => { + let wanted = match pin { + Some(c) => Some(c) + None => ctx.state.get(name).map(i => i.channel) + } + let (ch, tags) = locate(ctx, name, wanted) + let versions = sorted_versions(tags) + let version = match + versions.search_by(v => satisfies_all(v, [constraint])) { + Some(i) => versions[i] + None => + raise OrbitError( + "no version of \{ch.name}::\{name} matches '\{constraint}'", + ) + } + (ch, version, resolve_digest(ch, name, version)) + } + } + let m = fetch_manifest_cached(ctx.root, ch, name, digest) + let status = match ctx.state.get(name) { + Some(p) => "not installed; \{p.version} from \{p.channel} is" + None => "not installed" + } + println("\{name} \{version} (\{status})") + print_details(available_details(m, channel=ch.name, digest~), " ") } ///|