Skip to content

Commit 50acabe

Browse files
lessuselesslessuseless
authored andcommitted
Add GitHub Actions CI, Nix flake, and tests
1 parent 939b5d7 commit 50acabe

3 files changed

Lines changed: 125 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
test:
11+
name: Run Typst Tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Typst
18+
uses: typst-community/setup-typst@v3
19+
with:
20+
typst-version: 'latest' # Uses the latest official Typst release
21+
22+
- name: Compile Test File
23+
# We compile the test file. If it panics due to failed assertions or typing issues, the step fails.
24+
run: typst compile tests/test.typ tests/test.pdf
25+
26+
# (Optional) You can upload the compiled test PDF to inspect if anything visual is rendered
27+
- name: Upload Test PDF
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: check-output
31+
path: tests/test.pdf
32+
retention-days: 1

flake.nix

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
description = "Promptyst: A contract-first Typst DSL for structured AI prompts";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
in
14+
{
15+
devShells.default = pkgs.mkShell {
16+
buildInputs = with pkgs; [
17+
typst
18+
# You can add other tools like `just` or `git` here if needed
19+
just
20+
];
21+
22+
shellHook = ''
23+
echo "Promptyst Typst Dev Environment Loaded!"
24+
typst --version
25+
'';
26+
};
27+
28+
# A basic check to ensure compilation passes in the Nix environment
29+
checks.default = pkgs.stdenv.mkDerivation {
30+
name = "promptyst-tests";
31+
src = ./.;
32+
buildInputs = [ pkgs.typst ];
33+
phases = [ "unpackPhase" "buildPhase" ];
34+
buildPhase = ''
35+
typst compile tests/test.typ out.pdf
36+
# If the above passes without panic, the tests succeed.
37+
touch $out
38+
'';
39+
};
40+
}
41+
);
42+
}

tests/test.typ

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// tests/test.typ
2+
// A simple integration test to ensure promptyst compiles successfully
3+
// without panicking on valid inputs.
4+
5+
#import "../lib.typ": *
6+
7+
#let ctx = p-context(
8+
id: "test-context",
9+
entries: (
10+
(key: "repo", value: "promptyst"),
11+
),
12+
)
13+
14+
#let sch = p-schema(
15+
id: "test-schema",
16+
fields: (
17+
(name: "status", type: "string", description: "The build status"),
18+
),
19+
)
20+
21+
#let cp = p-checkpoint(
22+
id: "test-checkpoint",
23+
after-step: 1,
24+
assertion: "Ensure tests run.",
25+
on-fail: "halt"
26+
)
27+
28+
#let my-prompt = p-prompt(
29+
id: "ci-test",
30+
version: "0.1.0",
31+
role: "You are a CI agent.",
32+
context: ctx,
33+
constraints: ("Be fast.",),
34+
steps: ("Run code.",),
35+
inputs: ((name: "code", type: "string", description: "The code to test."),),
36+
schema: sch,
37+
checkpoints: (cp,)
38+
)
39+
40+
#let rendered = render-prompt(my-prompt)
41+
42+
// Assert that the rendering outputs a string successfully
43+
#assert(type(rendered) == str)
44+
45+
// You can also add specific string match assertions if desired:
46+
#assert(rendered.contains("## Checkpoint: test-checkpoint"))
47+
#assert(rendered.contains("## Output Schema: test-schema"))
48+
49+
#align(center)[
50+
= Tests Passed Successfully!
51+
]

0 commit comments

Comments
 (0)