conformance

package
v0.23.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package conformance checks an implementation of the ActNow family protocol (spec §4–§11) against the reference behaviour, whether or not it uses actnowkit:

  • testdata/files and testdata/cases.json: a file of every kind, with the result a conforming reader must reach (read, read-only, corrupt, members to keep). Language-neutral: any implementation can load them.
  • Fixture: a temporary $FAMILY and $HUB ($FAMILY/models/hub; ACTNOW_FAMILY_DIR set for the test), snapshots in the Hugging Face layout, and peers — other family apps played by actnowkit itself.
  • FakeHub: a local Hugging Face endpoint that counts the bytes it serves and can pause a file mid-way.
  • Run: the automatable scenarios of spec §16.1 (model reuse, deletion protection, concurrent and resumed downloads, settings, shortcuts, uninstalled apps, forward compatibility), driving the app under test through small interfaces (ModelApp, Downloader, SettingsApp, ShortcutApp, OrphanCleaner). Scenarios whose interface the app does not implement are skipped.
  • Check: problems in a real family directory (cmd/actnow-conformance).

An app's test:

func TestFamilyConformance(t *testing.T) {
	conformance.Run(t, func(t *testing.T, fx *conformance.Fixture, bundleID string) any {
		return newMyAdapter(fx.Family.Root, fx.Hub, bundleID) // wraps the app's own code
	})
}

Index

Constants

View Source
const (
	AppUnderTest = "dev.hehehai.dicta.conformance"      // the app under test
	SecondApp    = "dev.hehehai.voxtnew.conformance"    // a second instance of the app under test
	PeerSmith    = "dev.hehehai.audiosmith.conformance" // peers, played by actnowkit
	PeerAuralink = "dev.hehehai.auralink.conformance"
	PeerGone     = "dev.hehehai.pik.conformance" // a peer that gets uninstalled
)

Bundle ids the scenarios use. They are test variants of family apps (spec §6.1), so that no real installation on the test Mac interferes: LaunchServices knows none of them.

Variables

View Source
var Files, _ = fs.Sub(testdata, "testdata/files")

Files are the sample files of every kind (testdata/files), the same files cases.json describes.

View Source
var Scenarios = []Scenario{
	{Name: "ReuseWithoutDownload", Spec: "§16.1 scenario 1, §7.10.1", Run: reuse},
	{Name: "DeleteKeepsSharedModel", Spec: "§16.1 scenario 2, §7.6", Run: deleteShared},
	{Name: "DeleteUnsharedModel", Spec: "§7.6 step 1.5", Run: deleteUnshared},
	{Name: "DeleteWithLostClaims", Spec: "§7.6 (v1.0.9: lost claims are unsure)", Run: deleteLostClaims},
	{Name: "DeleteForAllApps", Spec: "§7.6 step 1.6", Run: deleteForAll},
	{Name: "SharedRepoWithinApp", Spec: "§7.3 models, §7.6", Run: sharedWithinApp},
	{Name: "DeleteWhileDownloading", Spec: "§7.4", Run: deleteBusy},
	{Name: "DeleteWhileLoaded", Spec: "§7.6 step 1.4, §11.1", Run: deleteLoaded},
	{Name: "ConcurrentDownload", Spec: "§16.1 scenario 3, §7.4", Run: concurrentDownload},
	{Name: "ResumeOtherAppsDownload", Spec: "§16.1 scenario 4, §7.1", Run: resumeDownload},
	{Name: "SettingsFollowFamily", Spec: "§16.1 scenario 5, §9.3", Run: settingsFollow},
	{Name: "ShortcutConflict", Spec: "§16.1 scenario 7, §10.4", Run: shortcutConflict},
	{Name: "UninstalledAppCleanup", Spec: "§16.1 scenario 8, §7.6 step 4", Run: orphans},
	{Name: "ForwardCompatibleClaims", Spec: "§16.1 scenario 9, §5.1", Run: forwardClaims},
	{Name: "ForwardCompatibleSettings", Spec: "§16.1 scenario 9, §5.1", Run: forwardSettings},
}

Scenarios are the automatable checks of spec §16.1 and §5.1.

Functions

func FakeApp

func FakeApp(dir, name, bundleID string) (string, error)

FakeApp writes a minimal <dir>/<name>.app whose Info.plist names bundleID, and returns its path.

func File

func File(name string) ([]byte, error)

File reads one sample file.

func Kit

func Kit(t testing.TB, fx *Fixture, bundleID string) any

Kit is a Factory making KitApps.

func Run

func Run(t *testing.T, newApp Factory)

Run runs the scenarios against the app the factory makes. Each runs in a fresh fixture.

Types

type Case

type Case struct {
	File string `json:"file"`
	Kind string `json:"kind"` // schema kind expected: "settings", "models.claims"…
	// Result is "ok" (read and writable), "readOnly" (a newer major: read
	// what is understood, never write back), "corrupt" (treat as absent;
	// move aside before writing a new one) or "wrongKind".
	Result string `json:"result"`
	// Expect maps JSON pointers to the values a reader must find.
	Expect map[string]any `json:"expect,omitempty"`
	// Keep lists JSON pointers of members a read-modify-write must keep.
	Keep []string `json:"keep,omitempty"`
}

Case is a row of testdata/cases.json: a sample file and what a conforming reader must make of it (spec §5.1).

func Cases

func Cases() ([]Case, error)

Cases reads testdata/cases.json.

type CatalogApp added in v0.2.0

type CatalogApp interface {
	BundleID() string
	// UseModel registers installed repos (a model's main repo and its
	// auxiliary repos) as used by one catalogue model, as "Use them" or a
	// finished download does.
	UseModel(ctx context.Context, model string, refs ...models.Ref) error
	// RemoveModel is "Remove from <app>" for one catalogue model: each of
	// its repos is released, and deleted unless something (another app,
	// or another model of this app) still uses it.
	RemoveModel(ctx context.Context, model string, refs ...models.Ref) error
}

CatalogApp is an app whose catalogue entries can share repos (an auxiliary tokenizer used by two models). Claims then name every model using the repo (spec §7.3 "models").

type Downloader

type Downloader interface {
	BundleID() string
	// Download fetches ref from the Hugging Face endpoint into $HUB and
	// claims it.
	Download(ctx context.Context, endpoint string, ref models.Ref) error
}

Downloader is an app that downloads models.

type Factory

type Factory func(t testing.TB, fx *Fixture, bundleID string) any

Factory makes the adapter of the app under test with this bundle id, working in fx's directories.

type FakeHub

type FakeHub struct {
	URL string
	// contains filtered or unexported fields
}

FakeHub is a local Hugging Face endpoint serving fixture repos: the model info API (/api/models/<repo>/revision/<rev>) and file downloads (/<repo>/resolve/<rev>/<path>, with Range). It counts the bytes served per file and can pause a file after some bytes.

func NewFakeHub

func NewFakeHub(repos ...Repo) *FakeHub

NewFakeHub starts a fake endpoint serving repos; Close it when done.

func (*FakeHub) Close

func (h *FakeHub) Close()

Close stops the server (releasing paused requests).

func (*FakeHub) Pause

func (h *FakeHub) Pause(repo, path string, after int64) (reached <-chan struct{}, release func())

Pause makes the next responses of repo/path stop after `after` bytes of the file have been served in total, until Release. reached is closed when the pause point is hit.

func (*FakeHub) Served

func (h *FakeHub) Served() int64

Served is the bytes of file bodies served so far, all files.

func (*FakeHub) ServedOf

func (h *FakeHub) ServedOf(repo, path string) int64

ServedOf is the bytes served of one file of a repo.

type Fixture

type Fixture struct {
	T      testing.TB
	Family family.Dir
	Hub    string
	// Legacy is a Hugging Face cache beside it ($HF_HUB_CACHE for the
	// test), where a model library moved from (spec v1.0.9) would be.
	Legacy string
	// Apps is what the peers' discovery says (bundle id → state): peers
	// built by the fixture use it, so a test can mark an app uninstalled.
	Apps map[string]models.AppState
}

Fixture is a temporary family directory and model library.

func New

func New(t testing.TB) *Fixture

New makes a fixture under t.TempDir() and points ACTNOW_FAMILY_DIR at it for the test, so code that resolves the defaults lands there too: the model library is the family's default, $FAMILY/models/hub (spec v1.0.9). HF_HUB_CACHE points at Legacy, HF_HOME is cleared.

func (*Fixture) Claimed

func (fx *Fixture) Claimed(bundleID string, ref models.Ref) bool

Claimed reports whether bundleID's claims file names ref.

func (*Fixture) Claims

func (fx *Fixture) Claims(bundleID string) models.Claims

Claims reads an app's claims file.

func (*Fixture) Incomplete

func (fx *Fixture) Incomplete(repo string) []string

Incomplete lists the partial-download files left under a repo.

func (*Fixture) Install

func (fx *Fixture) Install(r Repo)

Install writes a repo into $HUB as a complete download would: blobs, relative links in snapshots/<commit>, refs/main.

func (*Fixture) Installed

func (fx *Fixture) Installed(ref models.Ref) bool

Installed reports whether ref is complete on disk (spec §7.5).

func (*Fixture) Peer

func (fx *Fixture) Peer(bundleID string) *models.Store

Peer is another family app played by actnowkit (the reference implementation), sharing the fixture's directories.

func (*Fixture) Register

func (fx *Fixture) Register(bundleID string, sc ...shortcuts.Shortcut) string

Register makes a peer installed in the spec's sense (§6.3): a fake .app under the fixture and a manifest pointing at it, with shortcuts if given. It returns the app's path.

func (*Fixture) Uninstall

func (fx *Fixture) Uninstall(bundleID string)

Uninstall deletes a registered peer's .app, as dragging it to the Trash does: its manifest and claims stay (spec §7.7).

type FixtureSystem

type FixtureSystem struct{}

FixtureSystem is discovery's view of the machine for a fixture: no app is known to LaunchServices or running, Info.plist files are read from disk. Adapters of the app under test may use it in place of the real system on a developer's Mac.

func (FixtureSystem) AppPaths

func (FixtureSystem) AppPaths(string) []string

func (FixtureSystem) BundleID

func (FixtureSystem) BundleID(appPath string) (string, error)

func (FixtureSystem) Running

func (FixtureSystem) Running(string) []registry.Process

type KitApp

type KitApp struct {
	// contains filtered or unexported fields
}

KitApp is the app under test played by actnowkit: the reference adapter, and an example of writing one. It implements every interface of the suite.

func (*KitApp) BundleID

func (k *KitApp) BundleID() string

func (*KitApp) CleanOrphans

func (k *KitApp) CleanOrphans(ctx context.Context, bundleID string) error

func (*KitApp) Conflicts

func (k *KitApp) Conflicts(ctx context.Context) ([]string, error)

func (*KitApp) Declare

func (k *KitApp) Declare(ctx context.Context, sc []shortcuts.Shortcut) error

func (*KitApp) Download

func (k *KitApp) Download(ctx context.Context, endpoint string, ref models.Ref) error

func (*KitApp) Effective

func (k *KitApp) Effective(ctx context.Context, key string) (string, error)

func (*KitApp) Remove

func (k *KitApp) Remove(ctx context.Context, ref models.Ref, allApps bool) error

func (*KitApp) RemoveModel added in v0.2.0

func (k *KitApp) RemoveModel(ctx context.Context, model string, refs ...models.Ref) error

func (*KitApp) Reuse

func (k *KitApp) Reuse(ctx context.Context, refs ...models.Ref) error

func (*KitApp) Set

func (k *KitApp) Set(ctx context.Context, key, value string) error

func (*KitApp) StopFollowing

func (k *KitApp) StopFollowing(ctx context.Context, key string) error

func (*KitApp) UseModel added in v0.2.0

func (k *KitApp) UseModel(ctx context.Context, model string, refs ...models.Ref) error

type ModelApp

type ModelApp interface {
	BundleID() string
	// Reuse is "Use them" on the first-run reuse card: register installed
	// models as used by the app (claims with origin "reused"), downloading
	// nothing.
	Reuse(ctx context.Context, refs ...models.Ref) error
	// Remove is the user deleting a model in the app; allApps is "Delete
	// for all apps…" (after its confirmation). It returns an error when
	// it could not (another app downloads the model).
	Remove(ctx context.Context, ref models.Ref, allApps bool) error
}

ModelApp is an app with local models.

type OrphanCleaner

type OrphanCleaner interface {
	// CleanOrphans deletes what only the uninstalled app bundleID used,
	// and its files in $FAMILY.
	CleanOrphans(ctx context.Context, bundleID string) error
}

OrphanCleaner is an app with the storage page's orphan clean-up.

type Problem

type Problem struct {
	Level   string // "error", "warning" or "info"
	Path    string
	Message string
}

Problem is something Check found.

func Check

func Check(d family.Dir, hub string, sys registry.System) []Problem

Check inspects a family directory (and, for claims, the model library hub) the way the spec says files must look: every file parses with its schema, permissions are 0700/0600, manifests and claims are consistent, no secret is stored, no stale temporary files. sys answers discovery's questions (registry.DefaultSystem on a Mac).

func (Problem) String

func (p Problem) String() string

type Repo

type Repo struct {
	Ref   models.Ref
	Files []RepoFile
}

Repo is a fixture repo at one commit.

func TestRepo

func TestRepo(repo, revision string, weightBytes int) Repo

TestRepo makes a repo with a config, a tokenizer and a weights file of weightBytes deterministic bytes (seeded by the repo name).

func (Repo) Size

func (r Repo) Size() int64

Size is the bytes of its files.

type RepoFile

type RepoFile struct {
	Path    string
	Content []byte
	// LFS files are named by their sha256, others by their git blob id
	// (as the Hub does).
	LFS bool
}

RepoFile is a file of a fixture repo.

func (RepoFile) BlobID

func (f RepoFile) BlobID() string

BlobID is the name of a file's blob: its sha256 when LFS, else its git blob id (sha1 of "blob <size>\0" + content).

type Scenario

type Scenario struct {
	Name string
	Spec string // the spec section or §16.1 scenario
	Run  func(t testing.TB, fx *Fixture, newApp Factory)
}

Scenario is one check.

type SettingsApp

type SettingsApp interface {
	BundleID() string
	// Set changes a shared setting as the user would in the app (written
	// to the family while the app follows it).
	Set(ctx context.Context, key, value string) error
	// StopFollowing is "Use a different setting for this app".
	StopFollowing(ctx context.Context, key string) error
	// Effective is the value the app uses now, after re-reading the family
	// file (as on activation).
	Effective(ctx context.Context, key string) (string, error)
}

SettingsApp is an app with the shared settings.

type ShortcutApp

type ShortcutApp interface {
	BundleID() string
	// Declare sets the app's shortcuts and writes its manifest.
	Declare(ctx context.Context, sc []shortcuts.Shortcut) error
	// Conflicts lists the bundle ids of installed apps with a shortcut
	// colliding with one of the app's.
	Conflicts(ctx context.Context) ([]string, error)
}

ShortcutApp is an app with global shortcuts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL