StructOp Handbook
Contents Examples Commands
Handbook / Build and test

Lifecycle guarantees

A lifecycle guarantee is a behaviour of the StructOp commands that you can rely on. StructOp’s automated tests verify each one on every change to the program, on macOS and on Linux (ARM64 and x86-64), for C and for Rust targets. Each section states the guarantee and shows it with output recorded with version 0.1.0.

On this page

The nine guarantees#

The examples were recorded with version 0.1.0 on macOS, in a C project whose intent.st names StructOp/core 2.2.1 and whose main.st is:

main.st
variable "Who" {
    type    = String
    default = "world"
}

ability "print" "Greeting" {
    message = "Hello, ${var.Who}"
}

A second plan reports no changes#

What you can rely on. After apply succeeds, structop plan reports no changes, and plan -detailed-exitcode exits with 0, until you change something. Touching a file, formatting it or applying again is not a change. A real edit is, and once it is applied the plan is empty again.

structop apply
$ structop apply
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.print.Greeting

Plan: 1 to add, 0 to change, 0 to destroy.

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Hello, world

After touch main.st intent.st, which changes the files’ times and not their text:

structop plan -detailed-exitcode · exit status 0
$ structop plan -detailed-exitcode
No changes. Your application matches the configuration.

A saved plan is applied exactly or refused#

What you can rely on. structop plan -out=FILE saves a plan. apply FILE carries out exactly that plan, or refuses it: when the project, its variables, the target, a provider version, the recorded state or the environment has changed since the plan was saved, and when the file was altered, damaged or saved by another version of StructOp. Every refusal exits with 1, and show FILE never prints a plan that apply FILE would not carry out.

structop plan -out=change.plan
$ structop plan -out=change.plan
  # program.app will be replaced
  ~ program.app (.structop/build/app)
      ~ ability.print.Greeting
          message: "Hello, ${var.Who}" -> "Hi, ${var.Who}"

Plan: 0 to add, 1 to change, 0 to destroy.

Saved the plan to: change.plan

To perform exactly these actions, run:
    structop apply "change.plan"

After main.st is edited again ("Hi" to "Hey"):

structop apply change.plan · exit status 1
$ structop apply change.plan
Error: saved plan is stale: the configuration changed; run structop plan again

A copy of the file with one word changed in its stored text, and a copy marked as the earlier format:

structop show · exit status 1
$ structop show edited.plan
Error: edited.plan is damaged: its plan does not match its fingerprint; make it again with structop plan -out=edited.plan
structop show · exit status 1
$ structop show old.plan
Error: old.plan was saved by an earlier structop; make it again with structop plan -out=old.plan

A failed build changes nothing recorded#

What you can rely on. When the C compiler or Cargo fails, apply exits with 2, and the recorded state and the program stay as they were. The next plan still shows the pending change. Once the cause is fixed, apply succeeds and the next plan reports no changes.

Here the default of Who was changed to "there" and the build was made to fail:

structop apply · exit status 2
$ structop apply
  # program.app will be replaced
  ~ program.app (.structop/build/app)
      ~ ability.print.Greeting
          var.Who: "world" -> "there"
      compile: cc -std=c11 -> broken-cc -std=c11

Plan: 0 to add, 1 to change, 0 to destroy.
cc: error: out of disk space
Error: the C compiler rejected the generated code in .structop/build/main.c
  Unless a message above points into a native expression (c"...") of yours, this is a bug in structop or in a provider template, not in your configuration.

When a compiler message names a line of the generated source, StructOp adds a line under it that names the declaration the line came from, so the message leads back into your .st files.

The recorded state and the program were the same before and after. With the cause removed, apply built and ran the program, and then:

structop plan
$ structop plan
No changes. Your application matches the configuration.

A program that builds and then fails while running is a different case: the state is recorded before the program runs, apply exits with the program’s exit status, and the next plan reports no changes. Here an ability divides by zero:

structop apply · exit status 1
$ structop apply
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.value.zero
      + ability.print.Before
      + ability.print.Divide

Plan: 1 to add, 0 to change, 0 to destroy.

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

main.st:15:21: division by zero
before
structop plan
$ structop plan
No changes. Your application matches the configuration.

Installed providers are verified before use#

What you can rely on. init verifies each provider before it installs it, and every command that uses providers verifies the project’s copy again. A provider that was changed after it was installed, or that does not match its approved version, is refused, and nothing is built: your state, your program and your generated source stay as they were.

After a file of an installed provider was altered:

structop apply · exit status 1
$ structop apply
Error: provider StructOp/c 2.2.1 failed local package verification
  on intent.st line 9, column 9

Delete that provider from the project’s .structop/providers folder and run structop init to install a verified copy. A lock entry that does not match is refused in the same way:

structop plan · exit status 1
$ structop plan
Error: provider StructOp/c 2.2.1: the approved digest differs from the lock file
  on intent.st line 9, column 9
  Hint: Run "structop init -upgrade" to accept a different approved version.

The same declarations generate the same source#

What you can rely on. The same declarations, with the same StructOp and provider versions, generate byte-identical source, and for Rust the same Cargo files, whatever the folder, the home folder, the time zone or the language settings. Neither the generated source nor the recorded state holds an absolute path or a time stamp.

The same project applied in two folders, with different home folders, language settings and time zones:

comparing the generated source
$ shasum -a 256 d1/.structop/build/main.c d2/.structop/build/main.c
a0b0e8ec91800ba1066c640a40eb7a9a1967b7b03f474a252d8aa48eaf6b4fbb  d1/.structop/build/main.c
a0b0e8ec91800ba1066c640a40eb7a9a1967b7b03f474a252d8aa48eaf6b4fbb  d2/.structop/build/main.c

Environments are isolated#

What you can rely on. Each environment keeps its own state, generated source and program. Applying in one leaves the others as they were, deleting one leaves the others alone, and a plan saved in one environment is refused in another.

A plan saved in staging, applied after structop environment select default:

structop apply staging.plan · exit status 1
$ structop apply staging.plan
Error: saved plan is stale: the configuration changed; run structop plan again

Back in staging, the same file applies, and default is unchanged:

structop plan -environment=default
$ structop plan -environment=default
No changes. Your application matches the configuration.

structop test leaves the project untouched#

What you can rely on. structop test builds and runs every run in a temporary copy of the project. Every file of the project is the same before and after, for passing runs, failing runs and runs whose build fails. The copies are removed afterwards, and runs do not see each other’s variables or files.

structop test · exit status 1
$ structop test
tests/greeting.sttest
  PASS says_hello
  FAIL wrong_greeting
      output_contains: "Goodbye" not found
      output:
        Hello, world

Failure! 1 passed, 1 failed.

Every file of the project was the same before and after this run.

Missing or altered artefacts are detected#

What you can rely on. When the program, the generated source or a tracked export is deleted or changed outside StructOp, the next plan says so and gives the reason, and apply restores it; the plan is then empty. A state file that is damaged is refused by every command that reads it, with exit status 2, and nothing is overwritten.

After rm .structop/build/app:

structop plan
$ structop plan
  # program.app will be replaced
  ~ program.app (.structop/build/app)
      .structop/build/app is missing or was changed outside structop

Plan: 0 to add, 1 to change, 0 to destroy.

apply rebuilt the program and the next plan reported no changes. With the state file cut down to one character:

structop plan · exit status 2
$ structop plan
Error: .structop/state.json is damaged or was written by another structop version; delete it and run "structop apply"

init is all-or-nothing#

What you can rely on. init installs every provider the project names, or none. If any provider is refused or fails, nothing is installed or replaced and no lock is written, whatever the order of the providers in intent.st. A project that was initialised before keeps its providers and its lock, and an init that was interrupted is completed cleanly by the next one.

A C project that names StructOp/c and the Rust binding StructOp/gtk-rs:

structop init · exit status 1
$ structop init
Initializing provider plugins...
Error: provider "StructOp/gtk-rs" builds Rust programs, but this project has lang = "C"; use a provider for C
  on intent.st line 13, column 9

StructOp/c was not installed either, and .structop stayed empty:

structop plan · exit status 1
$ structop plan
Error: provider "StructOp/c" is not installed; run "structop init"
  on intent.st line 9, column 9

Scope of the guarantees#

The guarantees describe version 0.1.0 and grow with StructOp’s test suite. They cover the StructOp commands; these notes say where your own practice takes over.

The commands themselves are described in Commands and workflow and the command reference, the stages in Application development lifecycle, and providers and the lock in Configure providers.