Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Command Center (MCC)8 * File : services/internal/agent/journal/journal_test.go9 * Module : services10 * Repository : https://git.spboucher.ai/maclustr-command-center11 * Project Website : https://clustr.spboucher.ai12 * Created : 2026-11-1813 * Last Modified : 2026-11-1814 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142package journal4344import (45 "os"46 "path/filepath"47 "testing"48)4950func TestUnresolvedAfterCrash(t *testing.T) {51 path := filepath.Join(t.TempDir(), "commands.journal")52 j, open, err := Open(path)53 if err != nil || len(open) != 0 {54 t.Fatal(err, open)55 }56 j.Started("done", "diagnostic.run")57 j.Finished("done")58 j.Started("crashed", "service.restart")59 j.Close() // the process dies here60 f, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0o600)61 f.WriteString(`{"id":"torn","ev`)62 f.Close()6364 j, open, err = Open(path)65 if err != nil || len(open) != 1 || open[0].ID != "crashed" || open[0].Type != "service.restart" {66 t.Fatalf("%v %+v", err, open)67 }68 j.Close()69 // Still unresolved until its unknown outcome has been reported.70 j, open, _ = Open(path)71 if len(open) != 1 {72 t.Fatalf("%+v", open)73 }74 j.Reported("crashed")75 j.Close()76 if _, open, _ = Open(path); len(open) != 0 {77 t.Fatalf("still unresolved: %+v", open)78 }79}80