Cthulhu is no longer a fork. Now it is a screen reader written in Golang.
This commit is contained in:
1 parent
a998fe67de
commit
069fc674dc
708 files changed
+112482
-532
No files matched your search
@@ -0,0 +1,177 @@
|
||||
// Cthulhu screen reader.
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// Authors: Storm Dragon, Angus Kola
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by the Free
|
||||
// Software Foundation, either version 3 of the License, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
// more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
||||
|
||||
package parity
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
var ErrSchema = errors.New("parity ledger schema")
|
||||
|
||||
const (
|
||||
StatusPending = "pending"
|
||||
StatusInProgress = "in-progress"
|
||||
StatusImplemented = "implemented"
|
||||
StatusAuditRequired = "audit-required"
|
||||
StatusAcceptedOmission = "accepted-omission"
|
||||
)
|
||||
|
||||
var allowedStatuses = map[string]struct{}{
|
||||
StatusPending: {},
|
||||
StatusInProgress: {},
|
||||
StatusImplemented: {},
|
||||
StatusAuditRequired: {},
|
||||
StatusAcceptedOmission: {},
|
||||
}
|
||||
|
||||
var columns = []string{
|
||||
"id",
|
||||
"python_source",
|
||||
"subsystem",
|
||||
"behavior",
|
||||
"owner",
|
||||
"go_destination",
|
||||
"status",
|
||||
"automated_evidence",
|
||||
"x11_evidence",
|
||||
"wayland_evidence",
|
||||
"speech_evidence",
|
||||
"braille_evidence",
|
||||
"notes",
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
ID string
|
||||
PythonSource string
|
||||
Subsystem string
|
||||
Behavior string
|
||||
Owner string
|
||||
GoDestination string
|
||||
Status string
|
||||
AutomatedEvidence string
|
||||
X11Evidence string
|
||||
WaylandEvidence string
|
||||
SpeechEvidence string
|
||||
BrailleEvidence string
|
||||
Notes string
|
||||
}
|
||||
|
||||
type ParseError struct {
|
||||
Row int
|
||||
Err error
|
||||
}
|
||||
|
||||
func (parseError *ParseError) Error() string {
|
||||
return fmt.Sprintf("row %d: %v", parseError.Row, parseError.Err)
|
||||
}
|
||||
|
||||
func (parseError *ParseError) Unwrap() error {
|
||||
return parseError.Err
|
||||
}
|
||||
|
||||
func Load(reader io.Reader) ([]Record, error) {
|
||||
csvReader := csv.NewReader(reader)
|
||||
csvReader.FieldsPerRecord = len(columns)
|
||||
csvReader.TrimLeadingSpace = true
|
||||
|
||||
header, err := csvReader.Read()
|
||||
if err != nil {
|
||||
return nil, &ParseError{Row: 1, Err: fmt.Errorf("%w: read header: %w", ErrSchema, err)}
|
||||
}
|
||||
for index, column := range header {
|
||||
if column != columns[index] {
|
||||
return nil, &ParseError{
|
||||
Row: 1,
|
||||
Err: fmt.Errorf("%w: column %d is %q, want %q", ErrSchema, index+1, column, columns[index]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ids := make(map[string]struct{})
|
||||
var records []Record
|
||||
for row := 2; ; row++ {
|
||||
fields, readErr := csvReader.Read()
|
||||
if errors.Is(readErr, io.EOF) {
|
||||
break
|
||||
}
|
||||
if readErr != nil {
|
||||
return nil, &ParseError{Row: row, Err: fmt.Errorf("read record: %w", readErr)}
|
||||
}
|
||||
record := Record{
|
||||
ID: fields[0],
|
||||
PythonSource: fields[1],
|
||||
Subsystem: fields[2],
|
||||
Behavior: fields[3],
|
||||
Owner: fields[4],
|
||||
GoDestination: fields[5],
|
||||
Status: fields[6],
|
||||
AutomatedEvidence: fields[7],
|
||||
X11Evidence: fields[8],
|
||||
WaylandEvidence: fields[9],
|
||||
SpeechEvidence: fields[10],
|
||||
BrailleEvidence: fields[11],
|
||||
Notes: fields[12],
|
||||
}
|
||||
if err := validate(record, row, ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
records = append(records, record)
|
||||
}
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func validate(record Record, row int, ids map[string]struct{}) error {
|
||||
for field, value := range map[string]string{
|
||||
"id": record.ID,
|
||||
"python_source": record.PythonSource,
|
||||
"subsystem": record.Subsystem,
|
||||
"behavior": record.Behavior,
|
||||
"status": record.Status,
|
||||
} {
|
||||
if value == "" {
|
||||
return &ParseError{Row: row, Err: fmt.Errorf("%w: %s is empty", ErrSchema, field)}
|
||||
}
|
||||
}
|
||||
if _, exists := allowedStatuses[record.Status]; !exists {
|
||||
return &ParseError{
|
||||
Row: row,
|
||||
Err: fmt.Errorf("%w: invalid status %q", ErrSchema, record.Status),
|
||||
}
|
||||
}
|
||||
if _, exists := ids[record.ID]; exists {
|
||||
return &ParseError{
|
||||
Row: row,
|
||||
Err: fmt.Errorf("%w: duplicate id %q", ErrSchema, record.ID),
|
||||
}
|
||||
}
|
||||
if record.GoDestination == "" && record.Status != StatusAcceptedOmission {
|
||||
return &ParseError{
|
||||
Row: row,
|
||||
Err: fmt.Errorf("%w: go_destination is empty for status %q", ErrSchema, record.Status),
|
||||
}
|
||||
}
|
||||
ids[record.ID] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FormatStatuses() string {
|
||||
return "pending, in-progress, implemented, audit-required, accepted-omission"
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Cthulhu screen reader.
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// Authors: Storm Dragon, Angus Kola
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by the Free
|
||||
// Software Foundation, either version 3 of the License, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
// more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
||||
|
||||
package parity
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadValidLedger(t *testing.T) {
|
||||
ledger := strings.Join([]string{
|
||||
strings.Join(columns, ","),
|
||||
"core-startup,src/cthulhu/cthulhu.py,core,start the screen reader,Storm Dragon,internal/app,pending,,,,,,initial inventory",
|
||||
"web-navigation,src/cthulhu/scripts/web/script.py,web,structural navigation,Storm Dragon,internal/script,pending,,,,,,initial inventory",
|
||||
}, "\n")
|
||||
|
||||
records, err := Load(strings.NewReader(ledger))
|
||||
if err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
if len(records) != 2 {
|
||||
t.Fatalf("record count = %d, want 2", len(records))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRejectsInvalidRecords(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ledger string
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "missing header",
|
||||
ledger: "id\n",
|
||||
wantErr: ErrSchema,
|
||||
},
|
||||
{
|
||||
name: "invalid status",
|
||||
ledger: strings.Join([]string{
|
||||
strings.Join(columns, ","),
|
||||
"one,source.py,core,behavior,owner,destination,unknown,,,,,,note",
|
||||
}, "\n"),
|
||||
wantErr: ErrSchema,
|
||||
},
|
||||
{
|
||||
name: "duplicate id",
|
||||
ledger: strings.Join([]string{
|
||||
strings.Join(columns, ","),
|
||||
"one,source.py,core,behavior,owner,destination,pending,,,,,,note",
|
||||
"one,source.py,core,behavior,owner,destination,pending,,,,,,note",
|
||||
}, "\n"),
|
||||
wantErr: ErrSchema,
|
||||
},
|
||||
{
|
||||
name: "missing destination",
|
||||
ledger: strings.Join([]string{
|
||||
strings.Join(columns, ","),
|
||||
"one,source.py,core,behavior,owner,,pending,,,,,,note",
|
||||
}, "\n"),
|
||||
wantErr: ErrSchema,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, err := Load(strings.NewReader(test.ledger))
|
||||
if !errors.Is(err, test.wantErr) {
|
||||
t.Fatalf("Load error = %v, want %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user