feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
@@ -53,6 +54,15 @@ func TestNewNeedCanonicalizesTimestampsToStoragePrecision(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeedRejectsTimestampsOutsideContractDateTimeRange(t *testing.T) {
|
||||
snapshot := validNeedSnapshot()
|
||||
snapshot.CreatedAt = time.Date(10000, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
snapshot.UpdatedAt = snapshot.CreatedAt
|
||||
if _, err := NewNeed(snapshot); !errors.Is(err, ErrInvalidNeed) {
|
||||
t.Fatalf("NewNeed(year 10000) error = %v, want ErrInvalidNeed", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeedReadinessRequiresLocationOnlyForConfirmedOfficeOrHybrid(t *testing.T) {
|
||||
snapshot := validNeedSnapshot()
|
||||
formats := []NeedWorkFormat{NeedWorkFormatRemote}
|
||||
@@ -197,6 +207,104 @@ func TestNeedSnapshotIsDefensiveAndRedacted(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeedRejectedSuggestionsArePrivateDefensiveAndBounded(t *testing.T) {
|
||||
snapshot := validNeedSnapshot()
|
||||
snapshot.RejectedSuggestions = []NeedRejectedSuggestion{{Field: NeedRejectedSkills, Value: "postgresql"}}
|
||||
need, err := NewNeed(snapshot)
|
||||
if err != nil {
|
||||
t.Fatalf("NewNeed() error = %v", err)
|
||||
}
|
||||
copied := need.Snapshot()
|
||||
copied.RejectedSuggestions[0].Value = "changed"
|
||||
if got := need.Snapshot().RejectedSuggestions[0].Value; got != "postgresql" {
|
||||
t.Fatalf("suppressed value changed through snapshot copy: %q", got)
|
||||
}
|
||||
if printed := fmt.Sprintf("%+v", need); strings.Contains(printed, "postgresql") {
|
||||
t.Fatalf("need formatting exposed a suppressed suggestion: %q", printed)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
suggestions []NeedRejectedSuggestion
|
||||
}{
|
||||
{name: "unknown field", suggestions: []NeedRejectedSuggestion{{Field: "role", Value: "owner"}}},
|
||||
{name: "empty value", suggestions: []NeedRejectedSuggestion{{Field: NeedRejectedSkills}}},
|
||||
{name: "not normalized", suggestions: []NeedRejectedSuggestion{{Field: NeedRejectedSkills, Value: "PostgreSQL"}}},
|
||||
{name: "duplicate", suggestions: []NeedRejectedSuggestion{
|
||||
{Field: NeedRejectedSkills, Value: "postgresql"}, {Field: NeedRejectedSkills, Value: "postgresql"},
|
||||
}},
|
||||
{name: "too many", suggestions: tooManyNeedRejectedSuggestions()},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
invalid := validNeedSnapshot()
|
||||
invalid.RejectedSuggestions = test.suggestions
|
||||
if _, err := NewNeed(invalid); !errors.Is(err, ErrInvalidNeed) {
|
||||
t.Fatalf("NewNeed() error = %v, want ErrInvalidNeed", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeedRejectsSnapshotThatExceedsSerializedStorageBound(t *testing.T) {
|
||||
snapshot := validNeedSnapshot()
|
||||
controlText := strings.Repeat("\x01", maxNeedSourceTextRunes)
|
||||
snapshot.SourceText = &controlText
|
||||
snapshot.RejectedSuggestions = make([]NeedRejectedSuggestion, MaxNeedRejectedSuggestions)
|
||||
for index := range snapshot.RejectedSuggestions {
|
||||
value := strings.Repeat("\x01", maxNeedTaskRunes-3) + fmt.Sprintf("%03d", index)
|
||||
snapshot.RejectedSuggestions[index] = NeedRejectedSuggestion{Field: NeedRejectedTasks, Value: value}
|
||||
}
|
||||
for index := 0; index < maxNeedSkillItems; index++ {
|
||||
quote := strings.Repeat("\x01", maxNeedQuoteRunes)
|
||||
snapshot.Requirements.RequiredSkills = append(snapshot.Requirements.RequiredSkills, NeedSkill{
|
||||
Name: fmt.Sprintf("skill-%02d", index), Status: NeedItemExtracted,
|
||||
Source: NeedValueSource{Origin: NeedValueExtractedFromText, Quote: "e,
|
||||
ExtractedInVersion: needPointer(int64(1)), ExtractionVersion: needPointer("rules.1")},
|
||||
})
|
||||
}
|
||||
for index := 0; index < maxNeedSkillItems; index++ {
|
||||
quote := strings.Repeat("\x01", maxNeedQuoteRunes)
|
||||
snapshot.Requirements.DesiredSkills = append(snapshot.Requirements.DesiredSkills, NeedSkill{
|
||||
Name: fmt.Sprintf("other-%02d", index), Status: NeedItemExtracted,
|
||||
Source: NeedValueSource{Origin: NeedValueExtractedFromText, Quote: "e,
|
||||
ExtractedInVersion: needPointer(int64(1)), ExtractionVersion: needPointer("rules.1")},
|
||||
})
|
||||
}
|
||||
|
||||
_, err := NewNeed(snapshot)
|
||||
if !errors.Is(err, ErrInvalidNeed) || !strings.Contains(fmt.Sprint(err), "/rejected_suggestions") {
|
||||
t.Fatalf("NewNeed(oversized snapshot) error = %v, want bounded snapshot validation error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreNeedAcceptsLegacySnapshotWithoutRejectedSuggestions(t *testing.T) {
|
||||
encoded, err := json.Marshal(validNeedSnapshot())
|
||||
if err != nil {
|
||||
t.Fatalf("marshal snapshot: %v", err)
|
||||
}
|
||||
var fields map[string]json.RawMessage
|
||||
if err := json.Unmarshal(encoded, &fields); err != nil {
|
||||
t.Fatalf("decode snapshot fields: %v", err)
|
||||
}
|
||||
delete(fields, "rejected_suggestions")
|
||||
legacy, err := json.Marshal(fields)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal legacy snapshot: %v", err)
|
||||
}
|
||||
var snapshot NeedSnapshot
|
||||
if err := json.Unmarshal(legacy, &snapshot); err != nil {
|
||||
t.Fatalf("decode legacy snapshot: %v", err)
|
||||
}
|
||||
need, err := RestoreNeed(snapshot)
|
||||
if err != nil {
|
||||
t.Fatalf("RestoreNeed(legacy) error = %v", err)
|
||||
}
|
||||
if got := need.Snapshot().RejectedSuggestions; got == nil || len(got) != 0 {
|
||||
t.Fatalf("legacy rejected suggestions = %#v, want an empty list", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeedRestoresContractProvenanceAndRejectsInvalidValues(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -236,18 +344,24 @@ func TestNeedRestoresContractProvenanceAndRejectsInvalidValues(t *testing.T) {
|
||||
|
||||
func TestNeedRejectsInvalidUTF8InContractText(t *testing.T) {
|
||||
invalid := string([]byte{0xff})
|
||||
nul := "role\x00name"
|
||||
tests := []struct {
|
||||
name string
|
||||
change func(*NeedSnapshot)
|
||||
}{
|
||||
{name: "title", change: func(snapshot *NeedSnapshot) { snapshot.Title = invalid }},
|
||||
{name: "source text", change: func(snapshot *NeedSnapshot) { snapshot.SourceText = &invalid }},
|
||||
{name: "title with NUL", change: func(snapshot *NeedSnapshot) { snapshot.Title = nul }},
|
||||
{name: "source text with NUL", change: func(snapshot *NeedSnapshot) { snapshot.SourceText = &nul }},
|
||||
{name: "provenance quote", change: func(snapshot *NeedSnapshot) {
|
||||
snapshot.Requirements.Specialization = NeedValue[SpecializationCode]{
|
||||
Status: NeedValueExtracted, Value: needPointer(SpecializationBackend), Source: textNeedSource(1),
|
||||
}
|
||||
snapshot.Requirements.Specialization.Source.Quote = &invalid
|
||||
}},
|
||||
{name: "skill name with NUL", change: func(snapshot *NeedSnapshot) {
|
||||
snapshot.Requirements.RequiredSkills = []NeedSkill{{Name: nul, Status: NeedItemConfirmed, Source: *manualNeedSource()}}
|
||||
}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
@@ -360,6 +474,14 @@ func confirmedNeedValue[T any](value T, source *NeedValueSource) NeedValue[T] {
|
||||
|
||||
func needPointer[T any](value T) *T { return &value }
|
||||
|
||||
func tooManyNeedRejectedSuggestions() []NeedRejectedSuggestion {
|
||||
suggestions := make([]NeedRejectedSuggestion, MaxNeedRejectedSuggestions+1)
|
||||
for index := range suggestions {
|
||||
suggestions[index] = NeedRejectedSuggestion{Field: NeedRejectedTasks, Value: fmt.Sprintf("task-%d", index)}
|
||||
}
|
||||
return suggestions
|
||||
}
|
||||
|
||||
func containsNeedField(fields []NeedMissingField, field NeedMissingFieldName) bool {
|
||||
for _, candidate := range fields {
|
||||
if candidate.Field == field {
|
||||
|
||||
Reference in new issue
Block a user