Skip to content

Commit

Permalink
test(kernel): add universal navigator tests (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Jul 2, 2024
1 parent 7d5815d commit abc3a11
Show file tree
Hide file tree
Showing 30 changed files with 347 additions and 129 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"icase",
"ineffassign",
"jibberjabber",
"Kontroller",
"leaktest",
"linecomment",
"linters",
Expand Down
16 changes: 8 additions & 8 deletions builders.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tv

import (
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/internal/kernel"
"github.com/snivilised/traverse/internal/types"
"github.com/snivilised/traverse/measure"
Expand All @@ -10,7 +9,7 @@ import (

type buildArtefacts struct {
o *pref.Options
nav core.Navigator
kc types.KernelController
plugins []types.Plugin
ext extent
}
Expand All @@ -34,7 +33,7 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
if optionsErr != nil {
return &buildArtefacts{
o: o,
nav: kernel.HadesNav(optionsErr),
kc: kernel.HadesNav(optionsErr),
ext: ext,
}, optionsErr
}
Expand All @@ -51,7 +50,7 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
if navErr != nil {
return &buildArtefacts{
o: o,
nav: kernel.HadesNav(navErr),
kc: kernel.HadesNav(navErr),
ext: ext,
}, navErr
}
Expand All @@ -60,13 +59,14 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
//
plugins, pluginsErr := bs.plugins.build(o,
artefacts.Mediator,
ext.plugin(artefacts.Mediator),
artefacts.Kontroller,
ext.plugin(artefacts),
)

if pluginsErr != nil {
return &buildArtefacts{
o: o,
nav: kernel.HadesNav(pluginsErr),
kc: kernel.HadesNav(pluginsErr),
ext: ext,
}, pluginsErr
}
Expand All @@ -77,7 +77,7 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {
if bindErr := p.Init(); bindErr != nil {
return &buildArtefacts{
o: o,
nav: artefacts.Navigator,
kc: artefacts.Kontroller,
plugins: plugins,
ext: ext,
}, bindErr
Expand All @@ -86,7 +86,7 @@ func (bs *Builders) buildAll() (*buildArtefacts, error) {

return &buildArtefacts{
o: o,
nav: artefacts.Navigator,
kc: artefacts.Kontroller,
plugins: plugins,
ext: ext,
}, nil
Expand Down
15 changes: 10 additions & 5 deletions director.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ifActive func(o *pref.Options, mediator types.Mediator) types.Plugin
// to activate features according to option selections. other plugins will
// be initialised after primary plugins
func activated(o *pref.Options, mediator types.Mediator,
kc types.KernelController,
others ...types.Plugin,
) (plugins []types.Plugin, err error) {
var (
Expand All @@ -42,7 +43,7 @@ func activated(o *pref.Options, mediator types.Mediator,
}

for _, plugin := range plugins {
err = plugin.Register()
err = plugin.Register(kc)

if err != nil {
return nil, err
Expand Down Expand Up @@ -88,8 +89,10 @@ func Prime(using *pref.Using, settings ...pref.Option) *Builders {

return ext.options(settings...)
}),
navigator: kernel.Builder(func(o *pref.Options, res *types.Resources) (*kernel.Artefacts, error) {
return kernel.New(using, o, &kernel.Benign{}, res), nil
navigator: kernel.Builder(func(o *pref.Options,
resources *types.Resources,
) (*kernel.Artefacts, error) {
return kernel.New(using, o, &kernel.Benign{}, resources), nil
}),
plugins: features(activated), // swap over features & activated
}
Expand Down Expand Up @@ -132,8 +135,10 @@ func Resume(was *Was, settings ...pref.Option) *Builders {

return ext.options(settings...)
}),
navigator: kernel.Builder(func(o *pref.Options, res *types.Resources) (*kernel.Artefacts, error) {
artefacts := kernel.New(&was.Using, o, resume.GetSealer(was), res)
navigator: kernel.Builder(func(o *pref.Options,
resources *types.Resources,
) (*kernel.Artefacts, error) {
artefacts := kernel.New(&was.Using, o, resume.GetSealer(was), resources)

return resume.NewController(was, artefacts), nil
}),
Expand Down
2 changes: 1 addition & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (d *driver) init() {
_ = m.Data
// now invoke session.finish
},
Matcher: services.TopicTraverseResult,
Matcher: services.TopicNavigationComplete,
})
}

Expand Down
23 changes: 18 additions & 5 deletions extent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
type extent interface {
using() *pref.Using
was() *pref.Was
plugin(types.Mediator) types.Plugin
plugin(*kernel.Artefacts) types.Plugin // !!! *kernel.Artefacts
options(...pref.Option) (*pref.Options, error)
navFS() fs.FS
resFS() fs.FS
complete() bool
}

type fileSystems struct {
Expand Down Expand Up @@ -48,18 +49,23 @@ func (ex *primeExtent) was() *pref.Was {
return nil
}

func (ex *primeExtent) plugin(types.Mediator) types.Plugin {
func (ex *primeExtent) plugin(*kernel.Artefacts) types.Plugin {
return nil
}

func (ex *primeExtent) options(settings ...pref.Option) (*pref.Options, error) {
return pref.Get(settings...)
}

func (ex *primeExtent) complete() bool {
return true
}

type resumeExtent struct {
baseExtent
w *pref.Was
loaded *pref.LoadInfo
rp *resume.Plugin
}

func (ex *resumeExtent) using() *pref.Using {
Expand All @@ -70,12 +76,15 @@ func (ex *resumeExtent) was() *pref.Was {
return ex.w
}

func (ex *resumeExtent) plugin(mediator types.Mediator) types.Plugin {
return &resume.Plugin{
func (ex *resumeExtent) plugin(artefacts *kernel.Artefacts) types.Plugin {
ex.rp = &resume.Plugin{
BasePlugin: kernel.BasePlugin{
Mediator: mediator,
Mediator: artefacts.Mediator,
},
Complete: artefacts.Completion,
}

return ex.rp
}

func (ex *resumeExtent) options(settings ...pref.Option) (*pref.Options, error) {
Expand All @@ -88,3 +97,7 @@ func (ex *resumeExtent) options(settings ...pref.Option) (*pref.Options, error)
//
return loaded.O, err
}

func (ex *resumeExtent) complete() bool {
return ex.rp.Complete()
}
4 changes: 2 additions & 2 deletions factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (f *walkerFac) Configure() Director {
session{
sync: &sequential{
trunk: trunk{
nav: artefacts.nav,
kc: artefacts.kc,
o: artefacts.o,
ext: artefacts.ext,
err: err,
Expand Down Expand Up @@ -70,7 +70,7 @@ func (f *runnerFac) Configure() Director {
session{
sync: &concurrent{
trunk: trunk{
nav: artefacts.nav,
kc: artefacts.kc,
o: artefacts.o,
ext: artefacts.ext,
err: err,
Expand Down
22 changes: 17 additions & 5 deletions internal-traverse-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@ func (fn optionals) build(ext extent) (*pref.Options, error) {

// pluginsBuilder
type pluginsBuilder interface {
build(*pref.Options, types.Mediator, ...types.Plugin) ([]types.Plugin, error)
build(o *pref.Options,
mediator types.Mediator,
kc types.KernelController,
others ...types.Plugin,
) ([]types.Plugin, error)
}

type features func(*pref.Options, types.Mediator, ...types.Plugin) ([]types.Plugin, error)

func (fn features) build(o *pref.Options, mediator types.Mediator, others ...types.Plugin) ([]types.Plugin, error) {
return fn(o, mediator, others...)
type features func(*pref.Options,
types.Mediator,
types.KernelController,
...types.Plugin,
) ([]types.Plugin, error)

func (fn features) build(o *pref.Options,
mediator types.Mediator,
kc types.KernelController,
others ...types.Plugin,
) ([]types.Plugin, error) {
return fn(o, mediator, kc, others...)
}

type fsBuilder interface {
Expand Down
4 changes: 3 additions & 1 deletion internal/hiber/hibernate-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func (p *Plugin) Name() string {
return "hibernation"
}

func (p *Plugin) Register() error {
func (p *Plugin) Register(kc types.KernelController) error {
p.Kontroller = kc

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion internal/kernel/base-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import (
)

type BasePlugin struct {
Mediator types.Mediator
Mediator types.Mediator
Kontroller types.KernelController
}
18 changes: 12 additions & 6 deletions internal/kernel/builder.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
package kernel

import (
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/internal/types"
"github.com/snivilised/traverse/pref"
)

type (
Artefacts struct {
Navigator core.Navigator
Kontroller types.KernelController
Mediator types.Mediator
Facilities types.Facilities
Resources *types.Resources
Completion types.Completion
}

NavigatorBuilder interface {
Build(o *pref.Options, res *types.Resources) (*Artefacts, error)
Build(o *pref.Options,
resources *types.Resources,
) (*Artefacts, error)
}

Builder func(o *pref.Options, res *types.Resources) (*Artefacts, error)
Builder func(o *pref.Options,
resources *types.Resources,
) (*Artefacts, error)
)

func (fn Builder) Build(o *pref.Options, res *types.Resources) (*Artefacts, error) {
return fn(o, res)
func (fn Builder) Build(o *pref.Options,
resources *types.Resources,
) (*Artefacts, error) {
return fn(o, resources)
}
14 changes: 10 additions & 4 deletions internal/kernel/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ type (
invocationIt = collections.Iterator[types.Link]
)

type owned struct {
mums measure.Mutables
}

// anchor is a specialised link that should always be the
// last in the chain and contains the original client's handler.
type anchor struct {
target core.Client
mums measure.Mutables
owned owned
}

func (t *anchor) Next(node *core.Node) (bool, error) {
if metric := lo.Ternary(node.IsFolder(),
t.mums[enums.MetricNoFoldersInvoked],
t.mums[enums.MetricNoFilesInvoked],
t.owned.mums[enums.MetricNoFoldersInvoked],
t.owned.mums[enums.MetricNoFilesInvoked],
); metric != nil {
metric.Tick()
}
Expand Down Expand Up @@ -67,7 +71,9 @@ func newGuardian(callback core.Client,
stack := collections.NewStack[types.Link]()
stack.Push(&anchor{
target: callback,
mums: mums,
owned: owned{
mums: mums,
},
})

return &guardian{
Expand Down
4 changes: 4 additions & 0 deletions internal/kernel/kernel-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
type (
// NavigatorImpl
NavigatorImpl interface {
Starting(session types.Session)

// Top
Top(ctx context.Context,
ns *navigationStatic,
Expand All @@ -24,6 +26,8 @@ type (
ns *navigationStatic,
current *core.Node,
) (bool, error)

Result(ctx context.Context, err error) *types.KernelResult
}

// NavigatorDriver
Expand Down
Loading

0 comments on commit abc3a11

Please sign in to comment.