flexo

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 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 flexo drives a running Flexo MMS stack — the Layer 1 service and the SysML v2 API in front of it — so the RDF this project writes can be measured against what that service can actually read back, and so a project branch can be read and written as a model's repository: `sysml -sync-diff` and `-sync-apply` sync element-wise, `sysml -convert` reads a branch URL as notation or pushes a whole Turtle graph to it.

The standard API — projects, branches, commits, elements — is package sysmlapi's; this package adds what only Flexo has: the Layer 1 org a project lives under, its Turtle graph store, and the SPARQL read of a commit's graph.

The stack is external and opt-in; see .agents/skills/flexo-interop for how to bring it up and what the gate reports.

Index

Constants

View Source
const (
	EnvGate       = "FLEXO_INTEROP"
	EnvLayer1URL  = "FLEXO_LAYER1_URL"
	EnvSysMLV2URL = sysmlapi.EnvBaseURL
	EnvToken      = sysmlapi.EnvToken
	EnvOrg        = "FLEXO_SYSMLV2_ORG"
	EnvPlainHTTP  = sysmlapi.EnvPlainHTTP
)

Environment variables read by ConfigFromEnv. FLEXO_INTEROP is the gate: the live test skips unless it is set, exactly as the corpus gates skip on an absent corpus.

View Source
const (
	DefaultLayer1URL  = "http://localhost:8080"
	DefaultSysMLV2URL = sysmlapi.DefaultBaseURL
	DefaultOrg        = "sysmlv2"
)

Defaults matching flexo-mms-sysmlv2/docker-compose/docker-compose.yml, so a stack brought up from that file needs no configuration beyond the token.

View Source
const BranchID = "main"

BranchID is the default branch the harness asks for when it creates a project, so the graph endpoint's path is known rather than generated.

View Source
const PageSize = 10

PageSize is the page the harness asks the element listing for. It is smaller than the fixture, so a service that pages answers in more than one response.

Variables

View Source
var ErrBlankNode = errors.New("the graph holds a blank node, which no element id can address")

ErrBlankNode is a blank node in a graph read back from the stack; elements are IRIs, so a sync has no way to key one.

Functions

func SameEndpoint

func SameEndpoint(a, b string) bool

SameEndpoint reports whether two URLs name the same endpoint: scheme, host and effective port equal, path equal once trailing slashes are trimmed.

func Status

func Status(err error) int

Status returns the HTTP status of a failed request, or 0 if err is not one.

Types

type APIJSONStats

type APIJSONStats struct {
	Elements int
	Bytes    int
}

APIJSONStats describes the API element form the writer emitted for the same graph: how many element objects the commit post carried, and how large.

type ApplyReport

type ApplyReport struct {
	Fixture  string
	Revision string
	Rounds   []ApplyRound
	Findings []string
}

ApplyReport is a whole apply measurement.

func MeasureApply

func MeasureApply(ctx context.Context, c *Client, fixture string, model, revised []byte) (*ApplyReport, error)

MeasureApply applies model to a fresh project, then revised on top of it, then diffs revised against a change made behind the sync's back.

func (*ApplyReport) Text

func (r *ApplyReport) Text(header string) string

Text renders the report as the expectation file, in the same tab-separated form as the round-trip report.

type ApplyRound

type ApplyRound struct {
	Name      string
	Base      bool // the diff had the last-seen commit's graph as its base
	Creates   int
	Updates   int
	Deletes   int
	Conflicts int
	Uncarried []string // properties the representation left out of the comparison
	Changes   []string // "kind\tid\tmetaclass" per entry, in diff order
	Refused   string   // the refusal an unconfirmed or conflicted apply got, "" when appliable
	Applied   bool
	Commits   int      // commits the project has after the round
	Advanced  bool     // the sync state moved to the commit the stack named
	Readable  int      // written elements a direct read at that commit returned
	Absent    int      // deleted elements a direct read at that commit refused with 404
	Emptied   int      // deleted elements the read answered with an id and nothing else
	Present   int      // deleted elements the read still returned with content
	ReadBack  []string // "id\tproperty=value" for the properties an update changed
	Rediff    string   // the diff after the apply: counts, or "not run"
}

ApplyRound is one diff-and-apply against the branch.

type Branch

type Branch = sysmlapi.Branch

Branch is one branch as the SysML v2 API describes it: its id and the commit at its head.

type BranchRef

type BranchRef struct {
	SysMLV2URL string
	Project    string
	Branch     string
}

BranchRef is one project branch as a command-line URL names it; SysMLV2URL is the endpoint the URL spelled out, empty for the configured default.

func ParseBranchURL

func ParseBranchURL(raw string) (ref BranchRef, ok bool, err error)

ParseBranchURL resolves the branch URL forms a command line accepts, and reports ok=false for a string that is a file path rather than a URL:

http(s)://host[:port][/base]/projects/{project}/branches/{branch}
flexo://{project}/{branch}

type Client

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

Client talks to one stack: the standard API through a sysmlapi client, Layer 1 directly. It is safe for sequential use by one test.

func New

func New(cfg Config) *Client

New returns a client for cfg.

func (*Client) API added in v0.10.0

func (c *Client) API() *sysmlapi.Client

API is the standard SysML v2 API client the stack is driven through.

func (*Client) Branch

func (c *Client) Branch(ctx context.Context, project, branch string) (Branch, error)

Branch reads one branch of a project, head commit included.

func (*Client) BranchETag

func (c *Client) BranchETag(ctx context.Context, project, branch string) (string, error)

BranchETag reads the etag Layer 1's branch resource carries — the entity tag a conditional graph write quotes as its If-Match.

func (*Client) CommitGraph

func (c *Client) CommitGraph(ctx context.Context, project, commit string) (*rdf.Graph, error)

CommitGraph reads the model graph as one commit left it, through Layer 1's SPARQL endpoint, in the typed form the store holds rather than Turtle's shorthand.

func (*Client) Commits

func (c *Client) Commits(ctx context.Context, project string) ([]Commit, error)

Commits lists a project's commits, newest first as the service returns them.

func (*Client) Config

func (c *Client) Config() Config

Config returns the configuration the client was built with.

func (*Client) CreateProject

func (c *Client) CreateProject(ctx context.Context, id, name, branch string) (Project, error)

CreateProject creates a project through the SysML v2 API, which also creates its default branch and the queries scratch. The id doubles as the Layer 1 repo id, so it must satisfy the service's id rules; the default branch is named rather than left to the service, which would otherwise mint a uuid the graph endpoint's path needs.

func (*Client) ElementByID

func (c *Client) ElementByID(ctx context.Context, project, commit, id string) (Element, error)

ElementByID reads one element directly. A non-2xx answer is returned as the error, with Status(err) carrying the code: a rejected id is a finding, not a harness failure.

func (*Client) Elements

func (c *Client) Elements(ctx context.Context, project, commit string, pageSize int) (Listing, error)

Elements reads a commit's elements a page at a time.

func (*Client) EnsureOrg

func (c *Client) EnsureOrg(ctx context.Context) error

EnsureOrg creates the Layer 1 org the SysML v2 service keeps its projects under. A freshly initialized cluster does not have it, and every project creation fails until it does.

func (*Client) LoadTurtle

func (c *Client) LoadTurtle(ctx context.Context, project, branch string, turtle []byte, message string) error

LoadTurtle replaces a branch's model graph unconditionally: PutGraph with If-Match *, the precondition the measurement harness loads under.

func (*Client) PostChanges

func (c *Client) PostChanges(ctx context.Context, project, branch string, changes []byte) (Commit, error)

PostChanges commits SysML v2 JSON changes through the service's own commit path and returns the commit it made. An empty branch takes the default one.

func (*Client) PutGraph

func (c *Client) PutGraph(ctx context.Context, project, branch string, turtle []byte, message, ifMatch string) (PutResult, error)

PutGraph replaces a branch's model graph, conditional on ifMatch ("*" = any). 412 also answers a committed write, so the response headers are returned either way.

func (*Client) Reachable

func (c *Client) Reachable(ctx context.Context) error

Reachable reports whether both services answer. The SysML v2 project list is the cheapest authorized read on the stack.

func (*Client) Repository

func (c *Client) Repository(project, branch string) *Repository

Repository addresses one project branch for a sync.

func (*Client) Roots

func (c *Client) Roots(ctx context.Context, project, commit string) ([]Element, error)

Roots lists the elements the service considers roots of a commit: those with neither an owner nor an owning related element.

type Commit

type Commit = sysmlapi.Commit

Commit identifies one commit of a project.

type Config

type Config struct {
	Layer1URL  string // Layer 1 service, which owns orgs, repos, branches and graphs
	SysMLV2URL string // SysML v2 API, which owns projects, commits and elements
	Token      string // bearer token accepted by both services
	Org        string // Layer 1 org the SysML v2 service keeps its projects under
	Timeout    time.Duration
}

Config addresses one running stack.

func ConfigFromEnv

func ConfigFromEnv() (Config, error)

ConfigFromEnv reads the stack's addresses from the environment, defaulting to the published compose file's ports. The token has no default: it is a credential and is never written to the repository.

func (Config) CheckTransport

func (cfg Config) CheckTransport() error

CheckTransport refuses a token over plaintext to anything but a loopback host, unless the environment opts in with FLEXO_ALLOW_PLAIN_HTTP=1.

type Element

type Element = sysmlapi.Element

Element is one element as the SysML v2 API delivers it.

type ElementStat

type ElementStat struct {
	ID        string
	Type      string   // metaclass as written
	Listed    bool     // the paged element listing returned it
	Direct    string   // "ok", or "rejected(400)" / "absent(404)" for a direct read
	Written   int      // properties written for it, rdf:type excluded
	Delivered int      // properties returned for it, @type excluded
	Lost      []string // written properties the read path did not return
	Shape     []string // "sysml:type: reference written, string delivered"
}

ElementStat is one element's fate: whether the paged listing saw it, whether it can be read directly, and which of its properties came back.

type GraphStats

type GraphStats struct {
	Subjects    int
	Triples     int
	Bytes       int
	ByNamespace []PropertyStat // one entry per prefix, Written holding its triple count
}

GraphStats describes the Turtle this project produced, before any service saw it: the denominator of the measurement.

type Listing

type Listing = sysmlapi.Listing

Listing is one element listing: the elements it delivered, the number of responses it took, and whether the service ignored the paging parameters.

type PlaintextError

type PlaintextError = sysmlapi.PlaintextError

PlaintextError is a bearer token about to cross the network unencrypted: an http:// URL whose host is not this machine.

type Project

type Project = sysmlapi.Project

Project is the part of a created project the harness uses.

type PropertyStat

type PropertyStat struct {
	Property       string // "sysml:declaredName" written, "declaredName" delivered
	Written        int    // elements that carried it
	Delivered      int    // elements that returned it
	MultiValued    int    // elements that carried more than one value for it
	MultiDelivered int    // of those, the elements that returned it
}

PropertyStat is one predicate's fate across a whole side of the measurement: how many elements carried it, and on how many it came back.

type PutResult

type PutResult struct {
	Commit   string
	Location string
}

PutResult is the ETag and Location a graph write's response carries; a committed write has both, a refused 412 neither.

type Report

type Report struct {
	Fixture      string
	Graph        GraphStats
	APIJSONStats APIJSONStats
	Load         SideReport
	Reference    SideReport
	APIJSON      SideReport
	Findings     []string
}

Report is a whole run.

func Measure

func Measure(ctx context.Context, c *Client, fixture string, model, reference []byte) (*Report, error)

Measure loads model into the stack as Turtle and as JSON changes, reads both back, and reports what each side delivered. The reference argument is the JSON commit request; only its "change" array is posted.

func (*Report) Text

func (r *Report) Text(header string) string

Text renders the report as the expectation file: sections of tab-separated records, every list sorted, so a diff between two runs is a diff between two measurements.

type Repository

type Repository struct {
	*sysmlapi.Repository
	// contains filtered or unexported fields
}

Repository is one project branch as a sync's repository: read as a graph through Layer 1, written through the service's commit path so every element keeps its id, or replaced whole by a Turtle push. It remembers the head its last read stood at and refuses to commit past a head that has since moved.

func (*Repository) Graph

func (r *Repository) Graph(ctx context.Context) (*rdf.Graph, error)

Graph reads the branch as its head commit left it, so the read is of one commit rather than of a branch that may move under it.

func (*Repository) GraphAt

func (r *Repository) GraphAt(ctx context.Context, commit string) (*rdf.Graph, error)

GraphAt reads the branch as one earlier commit left it, through Layer 1's SPARQL endpoint: the last-seen graph a diff needs to tell a repository change from its own.

func (*Repository) Head

func (r *Repository) Head(ctx context.Context) (string, error)

Head is the branch's current head commit; a branch naming none is an error, as every Flexo branch stands at a commit.

func (*Repository) Push

func (r *Repository) Push(ctx context.Context, turtle []byte, message string) (string, error)

Push replaces the branch's whole model graph with the given Turtle and returns the commit made; a head that moved past what was seen is refused.

type Representation

type Representation = sysmlapi.Representation

Representation is what the service stores of a posted graph: sysml: properties only, values as JSON spells them. A diff under it converges with an apply.

type SideReport

type SideReport struct {
	Name          string // "graph-load", "json-commit" or "api-json-commit"
	Accepted      bool   // the service took the payload
	Refusal       string // why the service refused it, when it did
	Commits       int    // commits the project has after the write
	Written       int    // elements in the payload
	Listed        int    // written elements the listing returned
	Extra         int    // elements the listing returned that were not written
	Pages         int    // responses the listing took, at the harness page size
	IgnoredPaging bool   // the listing repeated or overran what the page size asked for
	Direct        int    // elements a direct read returned
	Roots         int    // elements the roots endpoint returned
	RootsInModel  int    // elements the payload itself gives no owner
	Elements      []ElementStat
	Properties    []PropertyStat
}

SideReport is one direction of the comparison: the graph this project loads, the reference model committed through the service's own JSON path, or the API's element form committed the same way.

type StaleBranchError

type StaleBranchError = sysmlapi.StaleBranchError

StaleBranchError is a branch whose head moved between the read a change set was computed against and the commit that would have written it; nothing was written, and the change set has to be recomputed against the new head.

type SupersededPushError

type SupersededPushError struct {
	Project, Branch, Commit, Head string
}

SupersededPushError is a committed graph write, named by its Location, whose branch head has since moved on; the baseline must come from reading the branch again.

func (*SupersededPushError) Error

func (e *SupersededPushError) Error() string

type UnrecordedPushError

type UnrecordedPushError struct {
	Project, Branch string
}

UnrecordedPushError is a graph write the branch accepted but whose response named no commit; a later head read could be another writer's, so none is recorded.

func (*UnrecordedPushError) Error

func (e *UnrecordedPushError) Error() string

type UnrepresentableError

type UnrepresentableError = sysmlapi.UnrepresentableError

UnrepresentableError is a value the service's JSON commit path has no spelling for; the diff refuses it rather than approximating.

Jump to

Keyboard shortcuts

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