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
- Variables
- func FakeApp(dir, name, bundleID string) (string, error)
- func File(name string) ([]byte, error)
- func Kit(t testing.TB, fx *Fixture, bundleID string) any
- func Run(t *testing.T, newApp Factory)
- type Case
- type CatalogApp
- type Downloader
- type Factory
- type FakeHub
- type Fixture
- func (fx *Fixture) Claimed(bundleID string, ref models.Ref) bool
- func (fx *Fixture) Claims(bundleID string) models.Claims
- func (fx *Fixture) Incomplete(repo string) []string
- func (fx *Fixture) Install(r Repo)
- func (fx *Fixture) Installed(ref models.Ref) bool
- func (fx *Fixture) Peer(bundleID string) *models.Store
- func (fx *Fixture) Register(bundleID string, sc ...shortcuts.Shortcut) string
- func (fx *Fixture) Uninstall(bundleID string)
- type FixtureSystem
- type KitApp
- func (k *KitApp) BundleID() string
- func (k *KitApp) CleanOrphans(ctx context.Context, bundleID string) error
- func (k *KitApp) Conflicts(ctx context.Context) ([]string, error)
- func (k *KitApp) Declare(ctx context.Context, sc []shortcuts.Shortcut) error
- func (k *KitApp) Download(ctx context.Context, endpoint string, ref models.Ref) error
- func (k *KitApp) Effective(ctx context.Context, key string) (string, error)
- func (k *KitApp) Remove(ctx context.Context, ref models.Ref, allApps bool) error
- func (k *KitApp) RemoveModel(ctx context.Context, model string, refs ...models.Ref) error
- func (k *KitApp) Reuse(ctx context.Context, refs ...models.Ref) error
- func (k *KitApp) Set(ctx context.Context, key, value string) error
- func (k *KitApp) StopFollowing(ctx context.Context, key string) error
- func (k *KitApp) UseModel(ctx context.Context, model string, refs ...models.Ref) error
- type ModelApp
- type OrphanCleaner
- type Problem
- type Repo
- type RepoFile
- type Scenario
- type SettingsApp
- type ShortcutApp
Constants ¶
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 ¶
var Files, _ = fs.Sub(testdata, "testdata/files")
Files are the sample files of every kind (testdata/files), the same files cases.json describes.
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 ¶
FakeApp writes a minimal <dir>/<name>.app whose Info.plist names bundleID, and returns its path.
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).
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 ¶
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 ¶
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 ¶
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.
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 ¶
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) Incomplete ¶
Incomplete lists the partial-download files left under a repo.
func (*Fixture) Install ¶
Install writes a repo into $HUB as a complete download would: blobs, relative links in snapshots/<commit>, refs/main.
func (*Fixture) Peer ¶
Peer is another family app played by actnowkit (the reference implementation), sharing the fixture's directories.
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
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) CleanOrphans ¶
func (*KitApp) RemoveModel ¶ added in v0.2.0
func (*KitApp) StopFollowing ¶
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 ¶
Problem is something Check found.
func Check ¶
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).
type Repo ¶
Repo is a fixture repo at one commit.
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.
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.