Merge remote-tracking branch 'origin/round/distro' into round/merge
# Conflicts: # CHANGELOG.md
This commit is contained in:
36 files changed
+4377
No files matched your search
Executable
+415
@@ -0,0 +1,415 @@
|
||||
#!/usr/bin/env python3
|
||||
"""The colourscheme of LLeMbas IDE, generated from the family's design tokens.
|
||||
|
||||
scripts/gen-ide-theme.py writes ide/config/colors/llembas.lua
|
||||
scripts/gen-ide-theme.py --check exits 1 when that file is not what the tokens give
|
||||
scripts/gen-ide-theme.py --tokens FILE --out FILE
|
||||
|
||||
The tokens file is the LLeMbas server's tokens.css, or the copy of its colour declarations in
|
||||
ide/tokens.css. Its two themes become the two halves of one colourscheme: `moria` when
|
||||
'background' is dark, `shire` when it is light. Every colour the editor draws comes out of this
|
||||
file's output; the configuration itself names highlight groups, never colours.
|
||||
|
||||
Standard library only.
|
||||
"""
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
THEMES = {"dark": "moria", "light": "shire"}
|
||||
NEEDED = [
|
||||
"bg", "bg-sunken", "surface", "surface-raised", "surface-hover", "surface-active", "border",
|
||||
"border-strong", "ink", "ink-muted", "ink-faint", "ink-inverse", "accent", "accent-hover",
|
||||
"accent-ink", "accent-soft", "selection", "leaf", "leaf-hover", "leaf-soft", "danger",
|
||||
"danger-soft", "success", "success-soft", "warning", "warning-soft",
|
||||
]
|
||||
|
||||
|
||||
def parse(css: str) -> dict:
|
||||
"""{theme: {token: value}} for the theme blocks of a tokens file."""
|
||||
out = {}
|
||||
for match in re.finditer(r"([^{}]*)\{([^{}]*)\}", css):
|
||||
names = re.findall(r'data-theme="([a-z0-9-]+)"', match.group(1))
|
||||
if not names:
|
||||
continue
|
||||
decls = dict(re.findall(r"--([a-z0-9-]+):\s*([^;]+);", match.group(2)))
|
||||
for name in names:
|
||||
out.setdefault(name, {}).update({k: " ".join(v.split()) for k, v in decls.items()})
|
||||
return out
|
||||
|
||||
|
||||
def rgb(value: str):
|
||||
value = value.strip()
|
||||
m = re.fullmatch(r"#([0-9A-Fa-f]{6})", value)
|
||||
if m:
|
||||
h = m.group(1)
|
||||
return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4)), 1.0
|
||||
m = re.fullmatch(r"rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([0-9.]+)\s*)?\)", value)
|
||||
if m:
|
||||
return (int(m.group(1)), int(m.group(2)), int(m.group(3))), float(m.group(4) or 1)
|
||||
raise ValueError(f"not a colour this generator reads: {value!r}")
|
||||
|
||||
|
||||
def mix(top, bottom, share):
|
||||
"""`share` of top over bottom."""
|
||||
return tuple(round(t * share + b * (1 - share)) for t, b in zip(top, bottom))
|
||||
|
||||
|
||||
def hexa(c):
|
||||
return "#{:02X}{:02X}{:02X}".format(*c)
|
||||
|
||||
|
||||
def palette(tokens: dict) -> dict:
|
||||
"""The tokens as opaque colours (a translucent one is laid over the background), plus the
|
||||
few mixes an editor needs that a web page does not."""
|
||||
missing = [n for n in NEEDED if n not in tokens]
|
||||
if missing:
|
||||
raise ValueError("the tokens file lacks: " + ", ".join(missing))
|
||||
bg, _ = rgb(tokens["bg"])
|
||||
p = {}
|
||||
for name in NEEDED:
|
||||
colour, alpha = rgb(tokens[name])
|
||||
p[name.replace("-", "_")] = colour if alpha >= 1 else mix(colour, bg, alpha)
|
||||
# What an editor needs between the tokens: all of them mixes of two tokens.
|
||||
p["line"] = mix(p["surface_hover"], p["bg"], 0.55) # the cursor's line
|
||||
p["ghost"] = mix(p["ink_faint"], p["bg"], 0.75) # text that is not there yet
|
||||
p["guide"] = mix(p["border"], p["bg"], 0.7) # whitespace, indent guides
|
||||
p["match"] = mix(p["warning"], p["bg"], 0.3) # a search match's background
|
||||
p["add_bg"] = mix(p["leaf"], p["bg"], 0.16)
|
||||
p["change_bg"] = mix(p["warning"], p["bg"], 0.14)
|
||||
p["delete_bg"] = mix(p["danger"], p["bg"], 0.16)
|
||||
p["text_bg"] = mix(p["warning"], p["bg"], 0.32)
|
||||
return {k: hexa(v) for k, v in p.items()}
|
||||
|
||||
|
||||
# group = (foreground, background, attributes) by palette name, or a link to another group.
|
||||
# One table for both themes: the palettes differ, the roles do not.
|
||||
GROUPS = [
|
||||
# --- the editor ---
|
||||
("Normal", "ink", "bg", ""),
|
||||
("NormalNC", "ink", "bg", ""),
|
||||
("NormalFloat", "ink", "surface", ""),
|
||||
("FloatBorder", "border_strong", "surface", ""),
|
||||
("FloatTitle", "leaf", "surface", "bold"),
|
||||
("FloatFooter", "ink_faint", "surface", ""),
|
||||
("Cursor", "bg", "ink", ""),
|
||||
("CursorLine", None, "line", ""),
|
||||
("CursorColumn", None, "line", ""),
|
||||
("ColorColumn", None, "surface", ""),
|
||||
("LineNr", "ink_faint", None, ""),
|
||||
("CursorLineNr", "leaf", "line", "bold"),
|
||||
("SignColumn", "ink_faint", "bg", ""),
|
||||
("FoldColumn", "ink_faint", "bg", ""),
|
||||
("Folded", "ink_muted", "surface", ""),
|
||||
("WinSeparator", "border", None, ""),
|
||||
("VertSplit", "border", None, ""),
|
||||
("Visual", None, "selection", ""),
|
||||
("VisualNOS", None, "selection", ""),
|
||||
("Search", "ink", "match", ""),
|
||||
("CurSearch", "ink_inverse", "warning", "bold"),
|
||||
("IncSearch", "ink_inverse", "warning", "bold"),
|
||||
("Substitute", "ink_inverse", "danger", ""),
|
||||
("MatchParen", "accent", "surface_active", "bold"),
|
||||
("NonText", "guide", None, ""),
|
||||
("Whitespace", "guide", None, ""),
|
||||
("SpecialKey", "guide", None, ""),
|
||||
("EndOfBuffer", "bg", None, ""),
|
||||
("Conceal", "ink_faint", None, ""),
|
||||
("Directory", "accent", None, ""),
|
||||
("Title", "leaf", None, "bold"),
|
||||
("ErrorMsg", "danger", None, ""),
|
||||
("WarningMsg", "warning", None, ""),
|
||||
("MoreMsg", "accent", None, ""),
|
||||
("ModeMsg", "ink_muted", None, ""),
|
||||
("Question", "accent", None, ""),
|
||||
("MsgArea", "ink", None, ""),
|
||||
("MsgSeparator", "border", "bg", ""),
|
||||
("QuickFixLine", None, "surface_active", "bold"),
|
||||
("WildMenu", "accent_ink", "accent", ""),
|
||||
("WinBar", "ink_muted", "bg", ""),
|
||||
("WinBarNC", "ink_faint", "bg", ""),
|
||||
("Pmenu", "ink", "surface_raised", ""),
|
||||
("PmenuSel", "accent_ink", "accent", ""),
|
||||
("PmenuKind", "ink_faint", "surface_raised", ""),
|
||||
("PmenuExtra", "ink_faint", "surface_raised", ""),
|
||||
("PmenuSbar", None, "surface_hover", ""),
|
||||
("PmenuThumb", None, "border_strong", ""),
|
||||
("PmenuMatch", "accent", None, "bold"),
|
||||
("PmenuMatchSel", "accent_ink", None, "bold"),
|
||||
("StatusLine", "ink", "surface_raised", ""),
|
||||
("StatusLineNC", "ink_faint", "surface", ""),
|
||||
("TabLine", "ink_muted", "surface", ""),
|
||||
("TabLineSel", "ink", "bg", "bold"),
|
||||
("TabLineFill", None, "bg_sunken", ""),
|
||||
("SpellBad", None, None, "undercurl sp=danger"),
|
||||
("SpellCap", None, None, "undercurl sp=warning"),
|
||||
("SpellRare", None, None, "undercurl sp=accent"),
|
||||
("SpellLocal", None, None, "undercurl sp=success"),
|
||||
# --- syntax ---
|
||||
("Comment", "ink_faint", None, "italic"),
|
||||
("Constant", "warning", None, ""),
|
||||
("String", "leaf", None, ""),
|
||||
("Character", "leaf", None, ""),
|
||||
("Number", "warning", None, ""),
|
||||
("Boolean", "warning", None, ""),
|
||||
("Float", "warning", None, ""),
|
||||
("Identifier", "ink", None, ""),
|
||||
("Function", "accent_hover", None, ""),
|
||||
("Statement", "accent", None, ""),
|
||||
("Conditional", "accent", None, ""),
|
||||
("Repeat", "accent", None, ""),
|
||||
("Label", "accent", None, ""),
|
||||
("Operator", "ink_muted", None, ""),
|
||||
("Keyword", "accent", None, ""),
|
||||
("Exception", "danger", None, ""),
|
||||
("PreProc", "success", None, ""),
|
||||
("Include", "accent", None, ""),
|
||||
("Define", "success", None, ""),
|
||||
("Macro", "success", None, ""),
|
||||
("Type", "success", None, ""),
|
||||
("StorageClass", "accent", None, ""),
|
||||
("Structure", "success", None, ""),
|
||||
("Typedef", "success", None, ""),
|
||||
("Special", "accent_hover", None, ""),
|
||||
("SpecialChar", "warning", None, ""),
|
||||
("Tag", "accent", None, ""),
|
||||
("Delimiter", "ink_muted", None, ""),
|
||||
("SpecialComment", "ink_muted", None, "italic"),
|
||||
("Debug", "danger", None, ""),
|
||||
("Underlined", "accent", None, "underline"),
|
||||
("Ignore", "ink_faint", None, ""),
|
||||
("Error", "danger", None, ""),
|
||||
("Todo", "ink_inverse", "warning", "bold"),
|
||||
("Added", "leaf", None, ""),
|
||||
("Changed", "warning", None, ""),
|
||||
("Removed", "danger", None, ""),
|
||||
("DiffAdd", None, "add_bg", ""),
|
||||
("DiffChange", None, "change_bg", ""),
|
||||
("DiffDelete", "danger", "delete_bg", ""),
|
||||
("DiffText", None, "text_bg", "bold"),
|
||||
# --- Treesitter and LSP, where the default link is not the role ---
|
||||
("@variable", "ink", None, ""),
|
||||
("@variable.builtin", "danger", None, ""),
|
||||
("@variable.parameter", "ink", None, "italic"),
|
||||
("@variable.member", "ink_muted", None, ""),
|
||||
("@property", "ink_muted", None, ""),
|
||||
("@constant.builtin", "warning", None, ""),
|
||||
("@module", "ink", None, ""),
|
||||
("@constructor", "success", None, ""),
|
||||
("@punctuation", "ink_muted", None, ""),
|
||||
("@tag", "accent", None, ""),
|
||||
("@tag.attribute", "success", None, ""),
|
||||
("@tag.delimiter", "ink_faint", None, ""),
|
||||
("@markup.heading", "leaf", None, "bold"),
|
||||
("@markup.strong", None, None, "bold"),
|
||||
("@markup.italic", None, None, "italic"),
|
||||
("@markup.link", "accent", None, "underline"),
|
||||
("@markup.raw", "warning", None, ""),
|
||||
("@markup.list", "accent", None, ""),
|
||||
("@markup.quote", "ink_muted", None, "italic"),
|
||||
("LspReferenceText", None, "surface_active", ""),
|
||||
("LspReferenceRead", None, "surface_active", ""),
|
||||
("LspReferenceWrite", None, "surface_active", ""),
|
||||
("LspInlayHint", "ghost", None, "italic"),
|
||||
("LspSignatureActiveParameter", "warning", None, "bold"),
|
||||
# --- diagnostics ---
|
||||
("DiagnosticError", "danger", None, ""),
|
||||
("DiagnosticWarn", "warning", None, ""),
|
||||
("DiagnosticInfo", "accent", None, ""),
|
||||
("DiagnosticHint", "success", None, ""),
|
||||
("DiagnosticOk", "leaf", None, ""),
|
||||
("DiagnosticVirtualTextError", "danger", "danger_soft", ""),
|
||||
("DiagnosticVirtualTextWarn", "warning", "warning_soft", ""),
|
||||
("DiagnosticVirtualTextInfo", "accent", "accent_soft", ""),
|
||||
("DiagnosticVirtualTextHint", "success", "success_soft", ""),
|
||||
("DiagnosticUnderlineError", None, None, "undercurl sp=danger"),
|
||||
("DiagnosticUnderlineWarn", None, None, "undercurl sp=warning"),
|
||||
("DiagnosticUnderlineInfo", None, None, "undercurl sp=accent"),
|
||||
("DiagnosticUnderlineHint", None, None, "undercurl sp=success"),
|
||||
("DiagnosticUnnecessary", "ink_faint", None, ""),
|
||||
# --- the bars ---
|
||||
("MiniStatuslineModeNormal", "ink_inverse", "leaf", "bold"),
|
||||
("MiniStatuslineModeInsert", "accent_ink", "accent", "bold"),
|
||||
("MiniStatuslineModeVisual", "ink_inverse", "warning", "bold"),
|
||||
("MiniStatuslineModeReplace", "ink_inverse", "danger", "bold"),
|
||||
("MiniStatuslineModeCommand", "ink_inverse", "success", "bold"),
|
||||
("MiniStatuslineModeOther", "ink_inverse", "ink_muted", "bold"),
|
||||
("MiniStatuslineDevinfo", "ink_muted", "surface_active", ""),
|
||||
("MiniStatuslineFilename", "ink", "surface_raised", ""),
|
||||
("MiniStatuslineFileinfo", "ink_muted", "surface_active", ""),
|
||||
("MiniStatuslineInactive", "ink_faint", "surface", ""),
|
||||
("MiniTablineCurrent", "ink", "bg", "bold"),
|
||||
("MiniTablineVisible", "ink_muted", "surface", ""),
|
||||
("MiniTablineHidden", "ink_faint", "bg_sunken", ""),
|
||||
("MiniTablineModifiedCurrent", "warning", "bg", "bold"),
|
||||
("MiniTablineModifiedVisible", "warning", "surface", ""),
|
||||
("MiniTablineModifiedHidden", "warning", "bg_sunken", ""),
|
||||
("MiniTablineFill", None, "bg_sunken", ""),
|
||||
("MiniTablineTabpagesection", "ink_inverse", "leaf", "bold"),
|
||||
("MiniTablineTrunc", "ink_faint", "bg_sunken", ""),
|
||||
# --- pickers, explorer, hints, git ---
|
||||
("MiniPickMatchCurrent", None, "surface_active", "bold"),
|
||||
("MiniPickMatchRanges", "accent", None, "bold"),
|
||||
("MiniPickPrompt", "leaf", "surface", "bold"),
|
||||
("MiniPickBorderText", "leaf", "surface", ""),
|
||||
("MiniFilesTitleFocused", "leaf", "surface", "bold"),
|
||||
("MiniFilesDirectory", "accent", None, ""),
|
||||
("MiniFilesCursorLine", None, "surface_active", ""),
|
||||
("MiniClueNextKey", "leaf", "surface", "bold"),
|
||||
("MiniClueNextKeyWithPostkeys", "warning", "surface", "bold"),
|
||||
("MiniClueDescGroup", "accent", "surface", ""),
|
||||
("MiniClueDescSingle", "ink", "surface", ""),
|
||||
("MiniClueSeparator", "border_strong", "surface", ""),
|
||||
("MiniClueTitle", "leaf", "surface", "bold"),
|
||||
("MiniDiffSignAdd", "leaf", None, ""),
|
||||
("MiniDiffSignChange", "warning", None, ""),
|
||||
("MiniDiffSignDelete", "danger", None, ""),
|
||||
("MiniDiffOverAdd", None, "add_bg", ""),
|
||||
("MiniDiffOverChange", None, "text_bg", ""),
|
||||
("MiniDiffOverChangeBuf", None, "change_bg", ""),
|
||||
("MiniDiffOverContext", None, "change_bg", ""),
|
||||
("MiniDiffOverContextBuf", None, None, ""),
|
||||
("MiniDiffOverDelete", None, "delete_bg", ""),
|
||||
("MiniIconsAzure", "accent", None, ""),
|
||||
("MiniIconsBlue", "accent", None, ""),
|
||||
("MiniIconsCyan", "success", None, ""),
|
||||
("MiniIconsGreen", "leaf", None, ""),
|
||||
("MiniIconsGrey", "ink_muted", None, ""),
|
||||
("MiniIconsOrange", "warning", None, ""),
|
||||
("MiniIconsPurple", "accent_hover", None, ""),
|
||||
("MiniIconsRed", "danger", None, ""),
|
||||
("MiniIconsYellow", "warning", None, ""),
|
||||
("BlinkCmpMenu", "ink", "surface_raised", ""),
|
||||
("BlinkCmpMenuBorder", "border_strong", "surface_raised", ""),
|
||||
("BlinkCmpMenuSelection", "accent_ink", "accent", ""),
|
||||
("BlinkCmpLabelMatch", "accent", None, "bold"),
|
||||
("BlinkCmpKind", "ink_faint", None, ""),
|
||||
("BlinkCmpDoc", "ink", "surface", ""),
|
||||
("BlinkCmpDocBorder", "border_strong", "surface", ""),
|
||||
# --- LLeMbas: the plugin's groups, and the IDE's own ---
|
||||
("LLeMbasBrand", "leaf", None, "bold"),
|
||||
("LLeMbasUserHeader", "accent", None, "bold"),
|
||||
("LLeMbasAgentHeader", "leaf", None, "bold"),
|
||||
("LLeMbasThought", "ink_faint", None, "italic"),
|
||||
("LLeMbasToolPending", "warning", None, ""),
|
||||
("LLeMbasToolDone", "success", None, ""),
|
||||
("LLeMbasToolFail", "danger", None, ""),
|
||||
("LLeMbasToolDenied", "danger", None, "italic"),
|
||||
("LLeMbasPlanHeader", "accent", None, "bold"),
|
||||
("LLeMbasDiffAdd", None, "add_bg", ""),
|
||||
("LLeMbasDiffDelete", "danger", "delete_bg", ""),
|
||||
("LLeMbasDiffHint", "ink_faint", None, "italic"),
|
||||
("LLeMbasGhost", "ghost", None, "italic"),
|
||||
("LLeMbasSeparator", "border", None, ""),
|
||||
("LLeMbasIdeLeaf", "leaf", None, ""),
|
||||
("LLeMbasIdeSign", "accent", None, ""),
|
||||
("LLeMbasIdeTitle", "ink", None, "bold"),
|
||||
("LLeMbasIdeVersion", "ink_faint", None, ""),
|
||||
("LLeMbasIdeKey", "leaf", None, "bold"),
|
||||
("LLeMbasIdeAction", "ink", None, ""),
|
||||
("LLeMbasIdeMuted", "ink_faint", None, ""),
|
||||
("LLeMbasIdeNote", "ink_muted", None, "italic"),
|
||||
("LLeMbasIdeGood", "success", None, ""),
|
||||
("LLeMbasIdeWarn", "warning", None, ""),
|
||||
("LLeMbasIdeStatus", "leaf", "surface_raised", ""),
|
||||
("LLeMbasIdeStatusOff", "ink_faint", "surface_raised", ""),
|
||||
]
|
||||
|
||||
# The terminal's sixteen colours, by palette name.
|
||||
TERMINAL = [
|
||||
"bg_sunken", "danger", "leaf", "warning", "accent", "accent_hover", "success", "ink_muted",
|
||||
"border_strong", "danger", "leaf_hover", "warning", "accent_hover", "accent_hover", "success", "ink",
|
||||
]
|
||||
|
||||
|
||||
def render(themes: dict) -> str:
|
||||
palettes = {}
|
||||
for background, name in THEMES.items():
|
||||
if name not in themes:
|
||||
raise ValueError(f'the tokens file has no data-theme="{name}" block')
|
||||
palettes[background] = palette(themes[name])
|
||||
keys = sorted(palettes["dark"])
|
||||
for _, fg, bg, attrs in GROUPS:
|
||||
for used in [fg, bg] + re.findall(r"sp=(\w+)", attrs):
|
||||
if used is not None and used not in keys:
|
||||
raise ValueError(f"a group names the colour {used}, which the palette lacks")
|
||||
out = [
|
||||
"-- LLeMbas: the colourscheme of LLeMbas IDE. moria when 'background' is dark, shire when light.",
|
||||
"-- GENERATED by scripts/gen-ide-theme.py from the design tokens. Do not edit: change the tokens",
|
||||
"-- or the generator, and run it again. Your own colours belong in lua/user/init.lua.",
|
||||
"local palettes = {",
|
||||
]
|
||||
for background in ("dark", "light"):
|
||||
out.append(f" {background} = {{ -- {THEMES[background]}")
|
||||
for key in keys:
|
||||
out.append(f' {key} = "{palettes[background][key]}",')
|
||||
out.append(" },")
|
||||
out += [
|
||||
"}",
|
||||
"",
|
||||
"local groups = {",
|
||||
]
|
||||
for name, fg, bg, attrs in GROUPS:
|
||||
parts = []
|
||||
if fg:
|
||||
parts.append(f'fg = "{fg}"')
|
||||
if bg:
|
||||
parts.append(f'bg = "{bg}"')
|
||||
for attr in attrs.split():
|
||||
if attr.startswith("sp="):
|
||||
parts.append(f'sp = "{attr[3:]}"')
|
||||
else:
|
||||
parts.append(f"{attr} = true")
|
||||
out.append(f' ["{name}"] = {{ {", ".join(parts)} }},')
|
||||
out += [
|
||||
"}",
|
||||
"",
|
||||
"local terminal = { " + ", ".join(f'"{name}"' for name in TERMINAL) + " }",
|
||||
"",
|
||||
'if vim.g.colors_name then vim.cmd("highlight clear") end',
|
||||
'vim.g.colors_name = "llembas"',
|
||||
'local p = palettes[vim.o.background == "light" and "light" or "dark"]',
|
||||
"for name, spec in pairs(groups) do",
|
||||
" local hl = {}",
|
||||
" for key, value in pairs(spec) do",
|
||||
' if key == "fg" or key == "bg" or key == "sp" then hl[key] = p[value] else hl[key] = value end',
|
||||
" end",
|
||||
" vim.api.nvim_set_hl(0, name, hl)",
|
||||
"end",
|
||||
'for i, name in ipairs(terminal) do vim.g["terminal_color_" .. (i - 1)] = p[name] end',
|
||||
"",
|
||||
"-- For the configuration: the palette in use, by token name.",
|
||||
"return p",
|
||||
"",
|
||||
]
|
||||
return "\n".join(out)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
||||
ap.add_argument("--tokens", type=Path, default=ROOT / "ide" / "tokens.css")
|
||||
ap.add_argument("--out", type=Path, default=ROOT / "ide" / "config" / "colors" / "llembas.lua")
|
||||
ap.add_argument("--check", action="store_true", help="write nothing; fail when the file is stale")
|
||||
args = ap.parse_args()
|
||||
try:
|
||||
text = render(parse(args.tokens.read_text(encoding="utf-8")))
|
||||
except (OSError, ValueError) as err:
|
||||
print(f"gen-ide-theme: {err}", file=sys.stderr)
|
||||
return 2
|
||||
if args.check:
|
||||
current = args.out.read_text(encoding="utf-8") if args.out.exists() else ""
|
||||
if current != text:
|
||||
print(f"gen-ide-theme: {args.out} is not what {args.tokens} gives; run scripts/gen-ide-theme.py", file=sys.stderr)
|
||||
return 1
|
||||
print(f"gen-ide-theme: {args.out.name} matches the tokens")
|
||||
return 0
|
||||
args.out.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.out.write_text(text, encoding="utf-8")
|
||||
print(f"gen-ide-theme: wrote {args.out}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
# What a release of LLeMbas IDE carries, written into dist/:
|
||||
# llembas-ide-<version>.tar.gz ide/ (the installer, the configuration, the lock files) and
|
||||
# nvim/ (the LLeMbas plugin), with VERSION and LICENSE
|
||||
# install.sh the installer, for: curl -fsSL <release>/install.sh | bash
|
||||
# SHA256SUMS of every release file in dist/ (the .vsix too, when it is there)
|
||||
# SHA256SUMS.sig with --sign <key file>: signed with ssh-keygen in the namespace
|
||||
# lembas-release, which install.sh checks once it is given the key
|
||||
#
|
||||
# scripts/package-ide.sh [--sign <ssh private key>]
|
||||
#
|
||||
# The archive is made from the files git tracks, in a fixed order with fixed times and owners, so
|
||||
# the same commit gives the same bytes. The version is the repository's VERSION file.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
sign=""
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--sign) sign="${2:?--sign needs a key file}" && shift ;;
|
||||
*) echo "package-ide: unknown option $1" >&2 && exit 2 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
version="$(tr -d '[:space:]' <VERSION)"
|
||||
name="llembas-ide-$version"
|
||||
python3 scripts/gen-ide-theme.py --check
|
||||
mkdir -p dist
|
||||
work="$(mktemp -d)"
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
|
||||
mkdir "$work/$name"
|
||||
git ls-files -z -- VERSION LICENSE ide nvim | grep -zv -E '^(ide|nvim)/tests/' |
|
||||
while IFS= read -r -d '' f; do
|
||||
mkdir -p "$work/$name/$(dirname "$f")"
|
||||
cp -p "$f" "$work/$name/$f"
|
||||
done
|
||||
chmod 755 "$work/$name/ide/install.sh" "$work/$name/ide/bin/llembas-ide"
|
||||
stamp="$(git log -1 --format=%ct)"
|
||||
tar -C "$work" --sort=name --mtime="@$stamp" --owner=0 --group=0 --numeric-owner -cf - "$name" | gzip -n -9 >"dist/$name.tar.gz"
|
||||
cp ide/install.sh dist/install.sh
|
||||
|
||||
(
|
||||
cd dist
|
||||
files=("$name.tar.gz" install.sh)
|
||||
[ ! -f "llembas-$version.vsix" ] || files+=("llembas-$version.vsix")
|
||||
sha256sum "${files[@]}" >SHA256SUMS
|
||||
)
|
||||
rm -f dist/SHA256SUMS.sig
|
||||
if [ -n "$sign" ]; then
|
||||
ssh-keygen -Y sign -q -f "$sign" -n lembas-release dist/SHA256SUMS
|
||||
fi
|
||||
echo "package-ide: dist/$name.tar.gz, dist/install.sh, dist/SHA256SUMS$([ -z "$sign" ] || echo ", dist/SHA256SUMS.sig")"
|
||||
Executable
+424
@@ -0,0 +1,424 @@
|
||||
#!/usr/bin/env bash
|
||||
# The tests of the LLeMbas IDE distribution (ide/): the scripts, a dry run, real installs into
|
||||
# temporary homes, a headless start checked from the inside, updating in place, failing without
|
||||
# leaving anything half-done, and uninstalling.
|
||||
#
|
||||
# scripts/test-ide.sh everything: also downloads the pinned Neovim (about 12 MB, its
|
||||
# SHA-256 checked) and compiles the Treesitter grammars, twice
|
||||
# scripts/test-ide.sh --quick no download and no compiling: the Neovim on this machine and
|
||||
# its bundled grammars only
|
||||
# scripts/test-ide.sh --update-readme rewrite the key table in ide/README.md from the key map
|
||||
#
|
||||
# Needs bash, git, curl, tar, shellcheck, python3 and a Neovim 0.10 or newer on PATH (or in
|
||||
# IDE_TEST_NVIM): the oldest supported one is what the installed IDE is also run on.
|
||||
# The plugins are fetched from GitHub at their pinned commits; LLEMBAS_IDE_GIT_MIRROR (a
|
||||
# directory of clones) spares the network. Nothing is written outside a temporary directory,
|
||||
# which is removed on every way out.
|
||||
# shellcheck disable=SC2016 # the small scripts given to bash -c are single-quoted on purpose
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
REPO="$PWD"
|
||||
|
||||
QUICK=0
|
||||
case "${1:-}" in
|
||||
--quick) QUICK=1 ;;
|
||||
--update-readme)
|
||||
nvim --headless -u NONE --cmd "set rtp+=ide/config" \
|
||||
-c 'lua io.stdout:write(table.concat(require("llembas_ide.keys").markdown(), "\n"))' -c q >ide/README.keys.tmp
|
||||
python3 - <<'PY'
|
||||
import re
|
||||
from pathlib import Path
|
||||
keys = Path("ide/README.keys.tmp").read_text(encoding="utf-8").strip()
|
||||
readme = Path("ide/README.md")
|
||||
text = readme.read_text(encoding="utf-8")
|
||||
text = re.sub(r"<!-- keys:begin -->\n.*?<!-- keys:end -->", lambda _: "<!-- keys:begin -->\n" + keys + "\n<!-- keys:end -->", text, flags=re.S)
|
||||
readme.write_text(text, encoding="utf-8")
|
||||
PY
|
||||
rm -f ide/README.keys.tmp
|
||||
echo "test-ide: ide/README.md has the key map's table"
|
||||
exit 0
|
||||
;;
|
||||
"") ;;
|
||||
*) echo "test-ide: unknown option $1" >&2 && exit 2 ;;
|
||||
esac
|
||||
|
||||
SYSTEM_NVIM="${IDE_TEST_NVIM:-$(command -v nvim || true)}"
|
||||
[ -n "$SYSTEM_NVIM" ] || { echo "test-ide: needs a Neovim on PATH (or IDE_TEST_NVIM)" >&2 && exit 2; }
|
||||
VERSION="$(tr -d '[:space:]' <VERSION)"
|
||||
WORK="$(mktemp -d "${TMPDIR:-/tmp}/llembas-ide-test.XXXXXX")"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
PASSED=0
|
||||
FAILED=0
|
||||
ok() {
|
||||
PASSED=$((PASSED + 1))
|
||||
printf ' ok %s\n' "$1"
|
||||
}
|
||||
fail() {
|
||||
FAILED=$((FAILED + 1))
|
||||
printf ' FAIL %s\n' "$1"
|
||||
[ -z "${2:-}" ] || printf '%s\n' "$2" | sed 's/^/ /' | tail -n 15
|
||||
}
|
||||
# check "name" command… passes when the command does
|
||||
check() {
|
||||
local name="$1" out
|
||||
shift
|
||||
if out="$("$@" 2>&1)"; then ok "$name"; else fail "$name" "$out"; fi
|
||||
}
|
||||
# attempt command… runs it; its output is in OUT and its exit status in RC
|
||||
OUT=""
|
||||
RC=0
|
||||
attempt() {
|
||||
if OUT="$("$@" 2>&1)"; then RC=0; else RC=$?; fi
|
||||
}
|
||||
passes() { if [ "$RC" = 0 ]; then ok "$1"; else fail "$1" "$OUT"; fi; }
|
||||
refuses() { if [ "$RC" != 0 ]; then ok "$1"; else fail "$1" "$OUT"; fi; }
|
||||
has() { grep -q -F -- "$2" <<<"$1"; }
|
||||
expect() { # expect "name" "text" "needle"
|
||||
if has "$2" "$3"; then ok "$1"; else fail "$1" "wanted: $3
|
||||
$2"; fi
|
||||
}
|
||||
|
||||
# PATH without any LLeMbas CLI of this machine: the tests decide whether there is one.
|
||||
CLEAN_PATH=""
|
||||
IFS=: read -r -a parts <<<"$PATH"
|
||||
for d in "${parts[@]}"; do
|
||||
if [ -n "$d" ] && [ ! -x "$d/lembas" ]; then CLEAN_PATH="${CLEAN_PATH:+$CLEAN_PATH:}$d"; fi
|
||||
done
|
||||
BG_DARK="$(sed -n '/data-theme="moria"/,/}/s/^ *--bg: *\(#[0-9A-Fa-f]*\);.*/\1/p' ide/tokens.css)"
|
||||
BG_LIGHT="$(sed -n '/data-theme="shire"/,/}/s/^ *--bg: *\(#[0-9A-Fa-f]*\);.*/\1/p' ide/tokens.css)"
|
||||
|
||||
# Run something as a person whose home is $1, with nothing of this machine's environment.
|
||||
as() {
|
||||
local home="$1"
|
||||
shift
|
||||
env -i PATH="$home/.local/bin:${EXTRA_PATH:+$EXTRA_PATH:}$CLEAN_PATH" HOME="$home" TERM=dumb LANG=C.UTF-8 \
|
||||
${LLEMBAS_IDE_GIT_MIRROR:+LLEMBAS_IDE_GIT_MIRROR="$LLEMBAS_IDE_GIT_MIRROR"} "$@"
|
||||
}
|
||||
installer() { # installer <home> <options…>
|
||||
local home="$1"
|
||||
shift
|
||||
as "$home" bash "$REPO/ide/install.sh" --no-cli "$@" 2>&1
|
||||
}
|
||||
# The headless checks, through the launcher. headless <home> <parsers 0|1> [VAR=value…]
|
||||
headless() {
|
||||
local home="$1" parsers="$2"
|
||||
shift 2
|
||||
(cd "$WORK" && as "$home" env IDE_TEST_REPO="$REPO" IDE_TEST_PARSERS="$parsers" IDE_TEST_BG_DARK="$BG_DARK" \
|
||||
IDE_TEST_BG_LIGHT="$BG_LIGHT" "$@" timeout 120 "$home/.local/bin/llembas-ide" --headless \
|
||||
-c "luafile $REPO/ide/tests/headless.lua" 2>&1)
|
||||
}
|
||||
typing() { # the completion menu, through the launcher
|
||||
local home="$1" out
|
||||
out="$( (cd "$WORK" && as "$home" timeout 60 "$home/.local/bin/llembas-ide" --headless -c "luafile $REPO/ide/tests/typing.lua" 2>&1) || true)"
|
||||
if grep -q -F 'ide-typing: the menu opens' <<<"$out"; then ok "$2"; else fail "$2" "$out"; fi
|
||||
}
|
||||
report_headless() { # report_headless "name" "output"
|
||||
local line
|
||||
line="$(grep -o -E 'ide-headless: [0-9]+ passed, 0 failed.*' <<<"$2" || true)"
|
||||
if [ -n "$line" ]; then ok "$1: ${line#ide-headless: }"; else fail "$1" "$2"; fi
|
||||
}
|
||||
startup_ms() { # the best of three starts, in milliseconds
|
||||
local home="$1" best="" ms i
|
||||
for i in 1 2 3; do
|
||||
rm -f "$WORK/startup.$i"
|
||||
as "$home" "$home/.local/bin/llembas-ide" --headless --startuptime "$WORK/startup.$i" -c 'qa!' >/dev/null 2>&1 || true
|
||||
ms="$(grep -F 'NVIM STARTED' "$WORK/startup.$i" 2>/dev/null | tail -n1 | awk '{ print $1 + 0 }')"
|
||||
if [ -n "$ms" ] && { [ -z "$best" ] || awk -v a="$ms" -v b="$best" 'BEGIN { exit !(a < b) }'; }; then best="$ms"; fi
|
||||
done
|
||||
echo "${best:-?}"
|
||||
}
|
||||
files_in() { (cd "$1" && find . -type f -o -type l | sort); }
|
||||
# A copy of what a release carries, to break on purpose.
|
||||
payload_copy() {
|
||||
local to="$1"
|
||||
mkdir -p "$to"
|
||||
git ls-files -z -- VERSION LICENSE ide nvim | while IFS= read -r -d '' f; do
|
||||
mkdir -p "$to/$(dirname "$f")"
|
||||
cp -p "$f" "$to/$f"
|
||||
done
|
||||
}
|
||||
|
||||
# --- 1. the files themselves -------------------------------------------------------------------
|
||||
echo "The scripts and the pins"
|
||||
check "shellcheck: install.sh, the launcher, the packaging and test scripts" \
|
||||
shellcheck ide/install.sh ide/bin/llembas-ide scripts/package-ide.sh scripts/test-ide.sh
|
||||
check "the colourscheme is what the tokens give" python3 scripts/gen-ide-theme.py --check
|
||||
check "install.sh runs nothing until its last line" bash -c '[ "$(tail -n1 ide/install.sh)" = "main \"\$@\"" ]'
|
||||
check "no sudo anywhere in the scripts" bash -c '! grep -n -w sudo ide/install.sh ide/bin/llembas-ide'
|
||||
check "no colour is written outside the generated theme" \
|
||||
bash -c '! grep -rn -E "#[0-9A-Fa-f]{6}\b" ide/config/init.lua ide/config/lua'
|
||||
check "every plugin is pinned to a full commit over https, under MIT, Apache-2.0, BSD or ISC" \
|
||||
bash -c 'grep -v -E "^\s*(#|$)" ide/plugins.lock | awk "{ if (\$3 !~ /^https:\/\/github\.com\// || \$4 !~ /^[0-9a-f]{40}\$/ || \$5 !~ /^(MIT|Apache-2\.0|BSD-[23]-Clause|ISC)\$/) { print; bad = 1 } } END { exit bad }"'
|
||||
check "every grammar is pinned to a full commit over https, under MIT, Apache-2.0, BSD or ISC" \
|
||||
bash -c 'grep -v -E "^\s*(#|$)" ide/parsers.lock | awk "{ if (\$2 !~ /^https:\/\/github\.com\// || \$3 !~ /^[0-9a-f]{40}\$/ || \$5 !~ /^(MIT|Apache-2\.0|BSD-[23]-Clause|ISC)\$/) { print; bad = 1 } } END { exit bad }"'
|
||||
check "THIRD_PARTY.md names every pinned commit" \
|
||||
bash -c 'for c in $(grep -v -E "^\s*(#|$)" ide/plugins.lock | awk "{ print \$4 }") $(grep -v -E "^\s*(#|$)" ide/parsers.lock | awk "{ print \$3 }"); do grep -q "$c" ide/THIRD_PARTY.md || { echo "missing $c"; exit 1; }; done'
|
||||
check "Neovim is pinned with a SHA-256 for each of the four platforms" \
|
||||
bash -c '[ "$(grep -c -E "^[0-9a-f]{64} nvim-(linux|macos)-(x86_64|arm64)\.tar\.gz$" ide/neovim.sha256)" = 4 ] && grep -q -E "^[0-9]+\.[0-9]+\.[0-9]+$" ide/neovim.version'
|
||||
check "nothing private in the tracked files" scripts/hygiene.sh
|
||||
check "the Lua of the configuration parses" \
|
||||
bash -c 'for f in ide/config/init.lua ide/config/colors/llembas.lua ide/config/lua/llembas_ide/*.lua ide/user-init.lua ide/tests/headless.lua; do "$0" --headless -u NONE -c "lua local f, e = loadfile([[$f]]); if not f then io.stdout:write(e) vim.cmd([[cquit 1]]) end" -c q || exit 1; done' "$SYSTEM_NVIM"
|
||||
|
||||
# --- 2. a dry run ------------------------------------------------------------------------------
|
||||
echo "A dry run"
|
||||
A="$WORK/a"
|
||||
mkdir -p "$A"
|
||||
out="$(installer "$A" --from-checkout --dry-run || true)"
|
||||
expect "says it is a dry run" "$out" "dry run: nothing is downloaded or written"
|
||||
case "$(uname -s)-$(uname -m)" in
|
||||
Linux-x86_64) ASSET=nvim-linux-x86_64 ;;
|
||||
Linux-aarch64 | Linux-arm64) ASSET=nvim-linux-arm64 ;;
|
||||
Darwin-arm64) ASSET=nvim-macos-arm64 ;;
|
||||
*) ASSET=nvim-macos-x86_64 ;;
|
||||
esac
|
||||
expect "names the pinned Neovim's address" "$out" "download https://github.com/neovim/neovim/releases/download/v$(cat ide/neovim.version)/$ASSET.tar.gz"
|
||||
expect "and its checksum" "$out" "check its SHA-256 is $(awk -v f="$ASSET.tar.gz" '$2 == f { print $1 }' ide/neovim.sha256)"
|
||||
while read -r name _ url commit _; do
|
||||
expect "names $name, its source and its commit" "$out" "fetch $name from $url at commit $commit"
|
||||
done < <(grep -v -E '^\s*(#|$)' ide/plugins.lock)
|
||||
expect "names the staging and the swap" "$out" "would swap the staged nvim/, site/pack/llembas/ and lib/ into $A/.local/share/llembas-ide"
|
||||
expect "names the launcher" "$out" "would write the launcher $A/.local/bin/llembas-ide"
|
||||
expect "names the person's own file" "$out" "would create $A/.config/llembas-ide/lua/user/init.lua"
|
||||
expect "names the menu entry" "$out" "would write the menu entry $A/.local/share/applications/llembas-ide.desktop"
|
||||
if [ -z "$(find "$A" -mindepth 1 | head -n1)" ]; then ok "writes nothing"; else fail "writes nothing" "$(find "$A" -mindepth 1 | head)"; fi
|
||||
out="$(as "$A" bash "$REPO/ide/install.sh" --from-checkout --dry-run 2>&1 || true)"
|
||||
expect "with the CLI missing, offers the CLI's own installer" "$out" "offer to install the LLeMbas CLI (beta) with its own installer"
|
||||
out="$(as "$A" bash "$REPO/ide/install.sh" --dry-run --version 9.9.9 2>&1 || true)"
|
||||
expect "from a release: names the archive and the checksum check" "$out" "releases/download/v9.9.9/llembas-ide-9.9.9.tar.gz"
|
||||
out="$(installer "$A" --from-checkout --prefix relative/dir 2>&1 || true)"
|
||||
expect "a relative --prefix is refused in words" "$out" "--prefix must be an absolute path"
|
||||
out="$(installer "$A" --from-checkout --nvim-bin /bin/true 2>&1 || true)"
|
||||
expect "a --nvim-bin that is not Neovim 0.10 or newer is refused in words" "$out" "older than Neovim 0.10"
|
||||
out="$(as "$A" bash -c 'cat "$1" | bash -s -- --from-checkout' _ "$REPO/ide/install.sh" 2>&1 || true)"
|
||||
expect "piped into bash, --from-checkout is refused in words" "$out" "--from-checkout needs this script run as a file"
|
||||
if [ -z "$(find "$A" -mindepth 1 | head -n1)" ]; then ok "refusals write nothing"; else fail "refusals write nothing" "$(find "$A" -mindepth 1 | head)"; fi
|
||||
|
||||
# --- 3. a real install, with the Neovim of this machine and its bundled grammars ---------------
|
||||
echo "A real install (the Neovim on this machine: $("$SYSTEM_NVIM" --version | head -n1), bundled grammars)"
|
||||
attempt installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers
|
||||
out="$OUT"
|
||||
passes "installs"
|
||||
expect "says so" "$out" "LLeMbas IDE $VERSION is installed"
|
||||
P="$A/.local/share/llembas-ide"
|
||||
check "the launcher, the configuration, the person's file, the menu entry and the icon are there" \
|
||||
test -x "$A/.local/bin/llembas-ide" -a -f "$A/.config/llembas-ide/init.lua" -a -f "$A/.config/llembas-ide/lua/user/init.lua" \
|
||||
-a -f "$A/.local/share/applications/llembas-ide.desktop" -a -f "$A/.local/share/icons/hicolor/256x256/apps/llembas-ide.png"
|
||||
check "the menu entry is a terminal application with the IDE's name" \
|
||||
bash -c 'grep -q "^Terminal=true$" "$1" && grep -q "^Name=LLeMbas IDE$" "$1" && grep -q "^Icon=llembas-ide$" "$1"' _ "$A/.local/share/applications/llembas-ide.desktop"
|
||||
stray="$(files_in "$A" | grep -v -E '^\./(\.local/share/llembas-ide/|\.config/llembas-ide/|\.local/bin/llembas-ide$|\.local/share/applications/llembas-ide\.desktop$|\.local/share/icons/hicolor/256x256/apps/llembas-ide\.png$|\.local/state/llembas-ide/|\.cache/llembas-ide/)' || true)"
|
||||
if [ -z "$stray" ]; then ok "nothing is written outside the IDE's own places"; else fail "nothing is written outside the IDE's own places" "$stray"; fi
|
||||
check "no ~/.config/nvim is made" test ! -e "$A/.config/nvim"
|
||||
if [ -z "$(find "$P" -maxdepth 1 \( -name '.staging.*' -o -name '.old.*' \) | head -n1)" ]; then ok "no staging directory is left"; else fail "no staging directory is left"; fi
|
||||
out="$(as "$A" "$A/.local/bin/llembas-ide" --version 2>&1 || true)"
|
||||
expect "--version: the IDE" "$out" "LLeMbas IDE $VERSION"
|
||||
expect "--version: Neovim" "$out" "Neovim $("$SYSTEM_NVIM" --version | sed -n '1s/^NVIM v//p')"
|
||||
expect "--version: the plugin" "$out" "LLeMbas plugin $VERSION"
|
||||
report_headless "headless start, from the inside" "$(headless "$A" 0 IDE_TEST_FIRST=1 || true)"
|
||||
typing "$A" "typing: the completion menu opens with the buffer's words, and <Tab> stays LLeMbas's"
|
||||
attempt as "$A" "$A/.local/bin/llembas-ide" doctor
|
||||
out="$OUT"
|
||||
passes "doctor finds the installation sound"
|
||||
expect "doctor: plugins at their pins" "$out" "ok mini.nvim $(awk '$1 == "mini.nvim" { print substr($4, 1, 12) }' ide/plugins.lock)"
|
||||
expect "doctor: says what is off without compiled grammars" "$out" "Treesitter grammars are not compiled"
|
||||
expect "doctor: says the CLI is missing and the editor works" "$out" "the LLeMbas CLI (lembas) is not installed"
|
||||
expect "doctor: a clean headless start" "$out" "every part of the IDE loads"
|
||||
START_A="$(startup_ms "$A")"
|
||||
ok "startup, best of three: ${START_A} ms"
|
||||
out="$(as "$A" "$A/.local/bin/llembas-ide" --headless -c 'lua io.stdout:write(vim.env.NVIM_APPNAME .. " " .. vim.fn.argv(0))' -c 'qa!' some-file.txt 2>&1 || true)"
|
||||
expect "arguments go through to Neovim" "$out" "llembas-ide some-file.txt"
|
||||
|
||||
# --- 4. again: an update in place --------------------------------------------------------------
|
||||
echo "Installing again"
|
||||
echo 'vim.g.llembas_ide_test_user = 42' >>"$A/.config/llembas-ide/lua/user/init.lua"
|
||||
# A plugin of the person's own, in the directory the README names.
|
||||
mkdir -p "$A/.config/llembas-ide/pack/user/start/mine/plugin"
|
||||
echo 'vim.g.llembas_ide_test_plugin = "loaded"' >"$A/.config/llembas-ide/pack/user/start/mine/plugin/mine.lua"
|
||||
user_before="$(sha256sum "$A/.config/llembas-ide/lua/user/init.lua")"
|
||||
attempt installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers
|
||||
out="$OUT"
|
||||
passes "installs over itself"
|
||||
if [ "$(grep -c 'already installed, unchanged' <<<"$out")" = "$(grep -c -v -E '^\s*(#|$)' ide/plugins.lock)" ]; then ok "keeps every plugin that is at its pin"; else fail "keeps every plugin that is at its pin" "$out"; fi
|
||||
expect "keeps the person's own file" "$out" "keep your $A/.config/llembas-ide/lua/user/init.lua as it is"
|
||||
if [ "$(sha256sum "$A/.config/llembas-ide/lua/user/init.lua")" = "$user_before" ]; then ok "the person's own file is byte for byte the same"; else fail "the person's own file is byte for byte the same"; fi
|
||||
report_headless "headless start again, with the person's file saying something" "$(headless "$A" 0 IDE_TEST_USER=1 || true)"
|
||||
echo '-- mine' >>"$A/.config/llembas-ide/init.lua"
|
||||
out="$(installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers || true)"
|
||||
expect "an init.lua the person edited is kept" "$out" "keep your edited $A/.config/llembas-ide/init.lua"
|
||||
check "and the IDE's own lies beside it" bash -c 'grep -q "^-- mine$" "$1/init.lua" && cmp -s "$1/init.lua.new" ide/config/init.lua' _ "$A/.config/llembas-ide"
|
||||
cp ide/config/init.lua "$A/.config/llembas-ide/init.lua"
|
||||
rm -f "$A/.config/llembas-ide/init.lua.new"
|
||||
# A plugin somebody changed is fetched again, not trusted.
|
||||
echo '-- changed' >>"$P/site/pack/llembas/start/conform.nvim/lua/conform/init.lua"
|
||||
out="$(as "$A" "$A/.local/bin/llembas-ide" doctor 2>&1 || true)"
|
||||
expect "doctor: a plugin whose files were changed is a failure" "$out" "FAIL conform.nvim is at its pin but its files were changed"
|
||||
out="$(installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers || true)"
|
||||
expect "the installer fetches that plugin again" "$out" "fetch conform.nvim from"
|
||||
check "and doctor is content" as "$A" "$A/.local/bin/llembas-ide" doctor
|
||||
|
||||
# --- 5. failing without leaving anything half-done ----------------------------------------------
|
||||
echo "Failures"
|
||||
before="$(files_in "$A" | grep -v -E '/(\.local/state|\.cache)/' | sha256sum)"
|
||||
payload_copy "$WORK/broken"
|
||||
echo 'error("broken on purpose")' >>"$WORK/broken/ide/config/lua/llembas_ide/options.lua"
|
||||
attempt as "$A" bash "$WORK/broken/ide/install.sh" --no-cli --from-dir "$WORK/broken" --nvim-bin "$SYSTEM_NVIM" --no-parsers
|
||||
out="$OUT"
|
||||
refuses "a configuration that does not start is refused"
|
||||
expect "in words" "$out" "the staged IDE did not start"
|
||||
expect "and says nothing was installed" "$out" "nothing installed"
|
||||
payload_copy "$WORK/wrongpin"
|
||||
sed -i -E 's/^(conform\.nvim .*)[0-9a-f]{6}( +MIT)/\1000000\2/' "$WORK/wrongpin/ide/plugins.lock"
|
||||
attempt as "$A" bash "$WORK/wrongpin/ide/install.sh" --no-cli --from-dir "$WORK/wrongpin" --nvim-bin "$SYSTEM_NVIM" --no-parsers
|
||||
out="$OUT"
|
||||
refuses "a commit that cannot be fetched stops the install"
|
||||
expect "in words" "$out" "could not fetch https://github.com/stevearc/conform.nvim at"
|
||||
if [ "$(files_in "$A" | grep -v -E '/(\.local/state|\.cache)/' | sha256sum)" = "$before" ]; then ok "after both, the installation has exactly the files it had"; else fail "after both, the installation has exactly the files it had"; fi
|
||||
if [ -z "$(find "$P" -maxdepth 1 \( -name '.staging.*' -o -name '.old.*' \) | head -n1)" ]; then ok "and no staging directory is left"; else fail "and no staging directory is left"; fi
|
||||
check "and it still starts" as "$A" "$A/.local/bin/llembas-ide" doctor
|
||||
E="$WORK/empty"
|
||||
mkdir -p "$E"
|
||||
out="$(as "$E" bash "$WORK/broken/ide/install.sh" --no-cli --from-dir "$WORK/broken" --nvim-bin "$SYSTEM_NVIM" --no-parsers 2>&1 || true)"
|
||||
left="$(files_in "$E")$(cd "$E" && find . -mindepth 1 -type d -name '*llembas*')"
|
||||
if [ -z "$left" ]; then ok "a failed first install leaves no file and no directory of the IDE's"; else fail "a failed first install leaves no file and no directory of the IDE's" "$left"; fi
|
||||
|
||||
# --- 6. with a LLeMbas CLI on PATH (a stand-in) -------------------------------------------------
|
||||
echo "With a LLeMbas CLI"
|
||||
mkdir -p "$WORK/cli/bin" "$WORK/cli/config"
|
||||
cat >"$WORK/cli/bin/lembas" <<EOF
|
||||
#!/bin/sh
|
||||
case "\$1" in
|
||||
--version) echo 2.0.0-beta.99 ;;
|
||||
__paths) printf 'config=%s\ndata=%s\nstate=%s\n' "$WORK/cli/config" "$WORK/cli/data" "$WORK/cli/state" ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$WORK/cli/bin/lembas"
|
||||
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" "$A/.local/bin/llembas-ide" doctor 2>&1 || true)"
|
||||
expect "doctor: finds it and its version" "$out" "LLeMbas CLI 2.0.0-beta.99"
|
||||
expect "doctor: not signed in" "$out" "not signed in: lembas login"
|
||||
printf '{ "instances": { "home": { "base_url": "https://llembas.example.org" } } }\n' >"$WORK/cli/config/lembas.json"
|
||||
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" "$A/.local/bin/llembas-ide" doctor 2>&1 || true)"
|
||||
expect "doctor: signed in" "$out" "signed in to a LLeMbas server"
|
||||
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" bash "$REPO/ide/install.sh" --from-checkout --dry-run 2>&1 || true)"
|
||||
expect "the installer leaves an installed CLI alone" "$out" "leave the LLeMbas CLI alone: it is installed"
|
||||
out="$(EXTRA_PATH="$WORK/cli/bin" as "$A" "$A/.local/bin/llembas-ide" --headless \
|
||||
-c 'lua local t, live = require("llembas_ide.llembas").status(); io.stdout:write(t .. " live=" .. tostring(live))' -c 'qa!' 2>&1 || true)"
|
||||
expect "the statusline shows LLeMbas and that suggestions are on" "$out" "◈ LLeMbas · suggest on live=true"
|
||||
|
||||
# --- 7. a release: packaged, checked, installed with the pinned Neovim and compiled grammars ----
|
||||
echo "A release"
|
||||
check "package-ide.sh writes the release files" scripts/package-ide.sh
|
||||
REL="$WORK/rel"
|
||||
mkdir -p "$REL/v$VERSION"
|
||||
cp "dist/llembas-ide-$VERSION.tar.gz" dist/install.sh dist/SHA256SUMS "$REL/v$VERSION/"
|
||||
check "SHA256SUMS lists the archive and the installer, and they match" \
|
||||
bash -c 'cd "$1" && sha256sum -c --quiet SHA256SUMS && grep -q " install.sh$" SHA256SUMS && grep -q " llembas-ide-.*\.tar\.gz$" SHA256SUMS' _ "$REL/v$VERSION"
|
||||
check "the release's install.sh is the repository's" cmp -s "$REL/v$VERSION/install.sh" ide/install.sh
|
||||
check "the archive holds the installer, the configuration, the plugin and no tests" \
|
||||
bash -c 't="$(tar -tzf "$1")"; for f in ide/install.sh ide/plugins.lock ide/config/init.lua nvim/plugin/llembas.lua VERSION LICENSE; do grep -q "^llembas-ide-$2/$f$" <<<"$t" || { echo "missing $f"; exit 1; }; done; ! grep -q "/tests/" <<<"$t"' _ "$REL/v$VERSION/llembas-ide-$VERSION.tar.gz" "$VERSION"
|
||||
B="$WORK/b"
|
||||
C="$WORK/c"
|
||||
mkdir -p "$B" "$C"
|
||||
# Tampered with: one byte of the archive changed.
|
||||
mkdir -p "$WORK/bad/v$VERSION"
|
||||
cp "$REL/v$VERSION"/* "$WORK/bad/v$VERSION/"
|
||||
printf 'x' >>"$WORK/bad/v$VERSION/llembas-ide-$VERSION.tar.gz"
|
||||
attempt as "$C" env LLEMBAS_IDE_RELEASE_BASE="file://$WORK/bad" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" --nvim-bin "$SYSTEM_NVIM" --no-parsers
|
||||
out="$OUT"
|
||||
refuses "an archive that does not match SHA256SUMS is refused"
|
||||
expect "in words" "$out" "does not match SHA256SUMS — nothing installed"
|
||||
out="$(as "$C" env LLEMBAS_IDE_RELEASE_BASE="http://example.org/releases" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" 2>&1 || true)"
|
||||
expect "a release over plain http is refused" "$out" "only https://"
|
||||
# Signed releases: a key made here, for this test only.
|
||||
ssh-keygen -q -t ed25519 -N '' -C test -f "$WORK/key" >/dev/null
|
||||
ssh-keygen -q -t ed25519 -N '' -C other -f "$WORK/otherkey" >/dev/null
|
||||
out="$(as "$C" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" --nvim-bin "$SYSTEM_NVIM" --no-parsers 2>&1 || true)"
|
||||
expect "with a release key set, an unsigned release is refused" "$out" "the release is not signed"
|
||||
ssh-keygen -Y sign -q -f "$WORK/otherkey" -n lembas-release "$REL/v$VERSION/SHA256SUMS" 2>/dev/null
|
||||
out="$(as "$C" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" --nvim-bin "$SYSTEM_NVIM" --no-parsers 2>&1 || true)"
|
||||
expect "one signed with another key is refused" "$out" "SHA256SUMS is not signed by the release key"
|
||||
if [ -z "$(find "$C" -mindepth 1 | head -n1)" ]; then ok "every refusal leaves nothing behind"; else fail "every refusal leaves nothing behind" "$(find "$C" -mindepth 1 | head)"; fi
|
||||
rm -f "$REL/v$VERSION/SHA256SUMS.sig"
|
||||
ssh-keygen -Y sign -q -f "$WORK/key" -n lembas-release "$REL/v$VERSION/SHA256SUMS" 2>/dev/null
|
||||
|
||||
if [ "$QUICK" = 1 ]; then
|
||||
attempt as "$B" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION" --nvim-bin "$SYSTEM_NVIM" --no-parsers
|
||||
out="$OUT"
|
||||
passes "installs from the release (quick: this machine's Neovim, bundled grammars)"
|
||||
expect "its signature is checked" "$out" "signature good (release key)"
|
||||
expect "its checksum is checked" "$out" "checksum good"
|
||||
report_headless "headless start of the release's install" "$(headless "$B" 0 IDE_TEST_FIRST=1 || true)"
|
||||
else
|
||||
attempt as "$B" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" bash "$REL/v$VERSION/install.sh" --no-cli --version "$VERSION"
|
||||
out="$OUT"
|
||||
passes "installs from the release, with the pinned Neovim downloaded and the grammars compiled"
|
||||
expect "its signature is checked" "$out" "signature good (release key)"
|
||||
expect "its checksum is checked" "$out" "checksum good"
|
||||
expect "Neovim's SHA-256 is checked before unpacking" "$out" "check its SHA-256 is"
|
||||
expect "the grammars are compiled" "$out" "compiled $(grep -c -v -E '^\s*(#|$)' ide/parsers.lock) Treesitter grammars"
|
||||
out="$(as "$B" "$B/.local/bin/llembas-ide" --version 2>&1 || true)"
|
||||
expect "the installed Neovim is the pinned one" "$out" "Neovim $(cat ide/neovim.version)"
|
||||
check "it is the IDE's own copy" test -x "$B/.local/share/llembas-ide/nvim/bin/nvim"
|
||||
report_headless "headless start on the pinned Neovim with compiled grammars" "$(headless "$B" 1 IDE_TEST_FIRST=1 || true)"
|
||||
typing "$B" "typing on the pinned Neovim: the completion menu opens, and <Tab> stays LLeMbas's"
|
||||
attempt as "$B" "$B/.local/bin/llembas-ide" doctor
|
||||
out="$OUT"
|
||||
passes "doctor finds it sound"
|
||||
expect "doctor: the grammars" "$out" "Treesitter grammars compiled"
|
||||
START_B="$(startup_ms "$B")"
|
||||
ok "startup on the pinned Neovim, best of three: ${START_B} ms"
|
||||
# A Neovim download that is not the pinned bytes.
|
||||
payload_copy "$WORK/wrongsha"
|
||||
sed -i -E 's/^[0-9a-f]{8}/00000000/' "$WORK/wrongsha/ide/neovim.sha256"
|
||||
attempt as "$C" bash "$WORK/wrongsha/ide/install.sh" --no-cli --from-dir "$WORK/wrongsha" --no-parsers
|
||||
out="$OUT"
|
||||
refuses "a Neovim download with another SHA-256 is refused"
|
||||
expect "in words" "$out" "not the pinned"
|
||||
if [ -z "$(find "$C" -mindepth 1 | head -n1)" ]; then ok "and leaves nothing behind"; else fail "and leaves nothing behind" "$(find "$C" -mindepth 1 | head)"; fi
|
||||
# The oldest supported Neovim with the compiled grammars: the first home, updated in place.
|
||||
attempt installer "$A" --from-checkout --nvim-bin "$SYSTEM_NVIM"
|
||||
out="$OUT"
|
||||
passes "the first home takes the compiled grammars in an update"
|
||||
report_headless "headless start on this machine's Neovim with compiled grammars" "$(headless "$A" 1 IDE_TEST_USER=1 || true)"
|
||||
fi
|
||||
attempt as "$B" env LLEMBAS_IDE_RELEASE_BASE="file://$REL" LLEMBAS_IDE_PUBKEY="$(cut -d' ' -f1,2 "$WORK/key.pub")" "$B/.local/bin/llembas-ide" update --no-cli --version "$VERSION"
|
||||
out="$OUT"
|
||||
passes "llembas-ide update runs the installed installer against the release"
|
||||
expect "and keeps what is already there" "$out" "already installed, unchanged"
|
||||
if [ "$QUICK" != 1 ]; then
|
||||
expect "Neovim included" "$out" "keep Neovim $(cat ide/neovim.version)"
|
||||
expect "and the compiled grammars" "$out" "compiled Treesitter grammars (already installed, same pins)"
|
||||
fi
|
||||
|
||||
# --- 8. somewhere else: --prefix -----------------------------------------------------------------
|
||||
echo "A prefix of the person's choosing"
|
||||
D="$WORK/d"
|
||||
mkdir -p "$D"
|
||||
attempt installer "$D" --from-checkout --nvim-bin "$SYSTEM_NVIM" --no-parsers --prefix "$WORK/opt/my ide"
|
||||
passes "installs into a directory with a space in its name"
|
||||
check "the IDE is there and not in the default place" test -d "$WORK/opt/my ide/lib" -a ! -e "$D/.local/share/llembas-ide"
|
||||
check "doctor is content" as "$D" "$D/.local/bin/llembas-ide" doctor
|
||||
attempt as "$D" "$D/.local/bin/llembas-ide" uninstall --purge --yes
|
||||
passes "uninstall --purge --yes"
|
||||
if [ -z "$(files_in "$D")" ] && [ ! -e "$WORK/opt/my ide" ]; then ok "leaves nothing, and the prefix is gone"; else fail "leaves nothing, and the prefix is gone" "$(files_in "$D"; ls -la "$WORK/opt")"; fi
|
||||
|
||||
# --- 9. uninstalling ---------------------------------------------------------------------------
|
||||
echo "Uninstalling"
|
||||
attempt as "$A" "$A/.local/bin/llembas-ide" uninstall --yes
|
||||
out="$OUT"
|
||||
passes "uninstall --yes"
|
||||
left="$(files_in "$A" | tr '\n' ' ')"
|
||||
if [ "$left" = "./.config/llembas-ide/lua/user/init.lua ./.config/llembas-ide/pack/user/start/mine/plugin/mine.lua " ]; then ok "leaves nothing but the person's own file and plugin"; else fail "leaves nothing but the person's own file and plugin" "$left"; fi
|
||||
check "which still has what the person wrote" grep -q 'llembas_ide_test_user = 42' "$A/.config/llembas-ide/lua/user/init.lua"
|
||||
attempt as "$B" "$B/.local/bin/llembas-ide" uninstall --purge --yes
|
||||
out="$OUT"
|
||||
passes "uninstall --purge --yes"
|
||||
left="$(files_in "$B")"
|
||||
if [ -z "$left" ]; then ok "leaves nothing at all"; else fail "leaves nothing at all" "$left"; fi
|
||||
left="$(cd "$B" && find . -mindepth 1 -type d -name '*llembas*')"
|
||||
if [ -z "$left" ]; then ok "not even an empty directory of its own"; else fail "not even an empty directory of its own" "$left"; fi
|
||||
|
||||
echo
|
||||
echo "test-ide: $PASSED passed, $FAILED failed$([ "$QUICK" = 1 ] && echo ' (quick)')"
|
||||
echo "test-ide: startup ${START_A} ms on $("$SYSTEM_NVIM" --version | head -n1)${START_B:+, ${START_B} ms on the pinned NVIM v$(cat ide/neovim.version) with compiled grammars}"
|
||||
[ "$FAILED" = 0 ]
|
||||
Reference in new issue
Block a user