<commit_before>
//
// specifying flon-tasker
//
// Fri Oct  3 11:24:25 JST 2014
//

#include "flutil.h"
#include "flutim.h"
#include "gajeta.h"
#include "djan.h"
#include "fl_ids.h"
#include "fl_common.h"
#include "fl_tasker.h"

#include "flon_helpers.h"


context "flon-tasker"
{
  before each
  {
    fgaj_conf_get()->logger = fgaj_grey_logger;
    fgaj_conf_get()->level = 5;
    fgaj_conf_get()->out = stderr;
    fgaj_conf_get()->params = "5p";

    chdir("../tst");
    flon_configure(".");

    char *s = NULL;
    fdja_value *v = NULL;

    char *exid = NULL;
    char *nid = NULL;
    char *path = NULL;
  }
  after each
  {
    free(s);
    fdja_free(v);

    free(exid);
    //free(nid); // no need
    free(path);
  }

  describe "flon_task()"
  {
    it "tasks"
    {
      exid = flon_generate_exid("ttest");
      nid = "0_0_7";
      path = flu_sprintf("var/spool/tsk/tsk_%s-%s.json", exid, nid);

      flu_writeall(
        path,
        "point: task\n"
        "state: created\n"
        "taskee: stamp\n"
        "tree: [ task, { _0: stamp }, [] ]\n"
        "exid: %s\n"
        "nid: %s\n"
        "payload: {\n"
          "hello: world\n"
        "}\n",
        exid, nid
      );

      int r = flon_task(path);

      expect(r i== 0);

      r = hlp_wait_for_file('f', "var/spool/dis/tsk_%s-%s.json", exid, nid, 3);
      expect(r i== 1);
      //
      flu_msleep(300);

      expect(flu_canopath(".") $==f "/tst/");

      expect(flu_fstat("var/spool/tsk/tsk_%s-%s.json", exid, nid) c== 'f');
        // it's still here, it's the dispatcher's work to nuke it

      expect(flu_fstat("var/spool/dis/tsk_%s-%s.json", exid, nid) c== 'f');

      v = fdja_parse_f("var/spool/dis/tsk_%s-%s.json", exid, nid);
      //fdja_putdc(v);

      expect(fdja_ls(v, "hello", NULL) ===f "world");
      expect(fdja_l(v, "stamp") != NULL);

      flu_unlink("var/spool/tsk/tsk_%s-%s.json", exid, nid);
      flu_unlink("var/spool/dis/ret_%s-%s.json", exid, nid);
    }

    it "moves non-identifiable tasks to var/spool/rejected/"
    {
      exid = flon_generate_exid("ttest");
      nid = "nada-nada-nada";
      path = flu_sprintf("var/spool/tsk/tsk_%s-%s.json", exid, nid);

      flu_writeall(
        path,
        "point: task\n"
        "state: created\n"
        "taskee: stamp\n"
        "tree: [ task, { _0: stamp }, [] ]\n"
        "exid: %s\n"
        "nid: %s\n"
        "payload: { a: b }\n",
        exid, nid
      );

      int r = flon_task(path);

      expect(r i== 1);

      expect(flu_fstat("var/spool/rejected/tsk_%s-%s.json", exid, nid) c== 'f');
    }

    it "moves non-parseable tasks to var/spool/rejected/"

    it "returns the task as failed if it can't find the taskee"
    {<commit_msg>spec "-tasker mvs non-parseable tsks to rejected/"<commit_after>
//
// specifying flon-tasker
//
// Fri Oct  3 11:24:25 JST 2014
//

#include "flutil.h"
#include "flutim.h"
#include "gajeta.h"
#include "djan.h"
#include "fl_ids.h"
#include "fl_common.h"
#include "fl_tasker.h"

#include "flon_helpers.h"


context "flon-tasker"
{
  before each
  {
    fgaj_conf_get()->logger = fgaj_grey_logger;
    fgaj_conf_get()->level = 5;
    fgaj_conf_get()->out = stderr;
    fgaj_conf_get()->params = "5p";

    chdir("../tst");
    flon_configure(".");

    char *s = NULL;
    fdja_value *v = NULL;

    char *exid = NULL;
    char *nid = NULL;
    char *path = NULL;
  }
  after each
  {
    free(s);
    fdja_free(v);

    free(exid);
    //free(nid); // no need
    free(path);
  }

  describe "flon_task()"
  {
    it "tasks"
    {
      exid = flon_generate_exid("ttest");
      nid = "0_0_7";
      path = flu_sprintf("var/spool/tsk/tsk_%s-%s.json", exid, nid);

      flu_writeall(
        path,
        "point: task\n"
        "state: created\n"
        "taskee: stamp\n"
        "tree: [ task, { _0: stamp }, [] ]\n"
        "exid: %s\n"
        "nid: %s\n"
        "payload: {\n"
          "hello: world\n"
        "}\n",
        exid, nid
      );

      int r = flon_task(path);

      expect(r i== 0);

      r = hlp_wait_for_file('f', "var/spool/dis/tsk_%s-%s.json", exid, nid, 3);
      expect(r i== 1);
      //
      flu_msleep(300);

      expect(flu_canopath(".") $==f "/tst/");

      expect(flu_fstat("var/spool/tsk/tsk_%s-%s.json", exid, nid) c== 'f');
        // it's still here, it's the dispatcher's work to nuke it

      expect(flu_fstat("var/spool/dis/tsk_%s-%s.json", exid, nid) c== 'f');

      v = fdja_parse_f("var/spool/dis/tsk_%s-%s.json", exid, nid);
      //fdja_putdc(v);

      expect(fdja_ls(v, "hello", NULL) ===f "world");
      expect(fdja_l(v, "stamp") != NULL);

      flu_unlink("var/spool/tsk/tsk_%s-%s.json", exid, nid);
      flu_unlink("var/spool/dis/ret_%s-%s.json", exid, nid);
    }

    it "moves non-identifiable tasks to var/spool/rejected/"
    {
      exid = flon_generate_exid("ttest");
      nid = "nada-nada-nada";
      path = flu_sprintf("var/spool/tsk/tsk_%s-%s.json", exid, nid);

      flu_writeall(
        path,
        "point: task\n"
        "state: created\n"
        "taskee: stamp\n"
        "tree: [ task, { _0: stamp }, [] ]\n"
        "exid: %s\n"
        "nid: %s\n"
        "payload: { a: b }\n",
        exid, nid
      );

      int r = flon_task(path);

      expect(r i== 1);

      expect(flu_fstat("var/spool/rejected/tsk_%s-%s.json", exid, nid) c== 'f');
    }

    it "moves non-parseable tasks to var/spool/rejected/"
    {
      exid = flon_generate_exid("ttest");
      nid = "0_2";
      path = flu_sprintf("var/spool/tsk/tsk_%s-%s.json", exid, nid);

      flu_writeall(path, "nada - nada - nada");

      int r = flon_task(path);

      expect(r i== 1);

      expect(flu_fstat("var/spool/rejected/tsk_%s-%s.json", exid, nid) c== 'f');
    }

    it "returns the task as failed if it can't find the taskee"
    {
{'fraction_non_alphanumeric': 0.1871997254632807, 'fraction_numerical': 0.009094028826355524, 'mean_word_length': 2.1731083287969515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4970711', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2445, 'n_words': 475}