<commit_before>var assert = require('chai').assert;
var fs = require('fs');
let LMLayer = require('../../build/headless');

/*
 * Shows off the LMLayer API, using the full prediction interface.
 * The dummy model (or mock model) is a language model which has 
 * **injectable** suggestions: that is, you, as the tester, have
 * to provide the predictions. The dummy model does not create any
 * suggestions on its own. The dummy model can take in a series
 * of suggestions when loaded and return them sequentially.
 */
describe('LMLayer using dummy model', function () {
  describe('Prediction', function () {
    it('will predict future suggestions (loaded from file)', function () {
      var lmLayer = new LMLayer(capabilities());

      var stripIDs = function(suggestions) {
        suggestions.forEach(function(suggestion) {
          delete suggestion.id;
        });
      }

      // We're testing many as asynchronous messages in a row.
      // this would be cleaner using async/await syntax.
      // Not done yet, as this test case is a slightly-edited copy of the in-browser version.
      return lmLayer.loadModel(
        // We're running headlessly, so the path can be relative to the npm root directory.
        "unit_tests/in_browser/resources/models/simple-dummy.js"
      ).then(function (actualConfiguration) {
        return Promise.resolve();
      }).then(function () {
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[0]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[1]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[2]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[3]);
        lmLayer.shutdown();
        return Promise.resolve();
      });
    });

    it('will predict future suggestions (loaded from raw source)', function () {
      var lmLayer = new LMLayer(capabilities());

      // We're running headlessly, so the path can be relative to the npm root directory.
      let modelCode = fs.readFileSync("./unit_tests/in_browser/resources/models/simple-dummy.js").toString();

      // We're testing many as asynchronous messages in a row.
      // this would be cleaner using async/await syntax.
      // Not done yet, as this test case is a slightly-edited copy of the in-browser version.
      return lmLayer.loadModel(
        modelCode, 'raw'
      ).then(function (actualConfiguration) {
        return Promise.resolve();
      }).then(function () {
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        assert.deepEqual(suggestions, iGotDistractedByHazel()[0]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        assert.deepEqual(suggestions, iGotDistractedByHazel()[1]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        assert.deepEqual(suggestions, iGotDistractedByHazel()[2]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        assert.deepEqual(suggestions, iGotDistractedByHazel()[3]);
        lmLayer.shutdown();
        return Promise.resolve();
      });
    });
  });

  describe('Wordbreaking', function () {
    it('will perform (default) wordbreaking and return word at caret', function () {
      var lmLayer = new LMLayer(capabilities());

      // We're testing many as asynchronous messages in a row.
      // this would be cleaner using async/await syntax.
      // Not done yet, as this test case is a slightly-edited copy of the in-browser version.
      return lmLayer.loadModel(
        // We're running headlessly, so the path can be relative to the npm root directory.
        "unit_tests/in_browser/resources/models/simple-dummy.js"
      ).then(function (actualConfiguration) {
        return Promise.resolve();
      }).then(function () {
        // We'll keep it simple here, as this is primarily an integration test.
        // Functionality is handled in the 'headless' test case 'default-word-breaker.js'.
        let context = { 
          left: 'The quick brown fox jumped', startOfBuffer: true,<commit_msg>fix(common/models): post-merge test required id strip<commit_after>var assert = require('chai').assert;
var fs = require('fs');
let LMLayer = require('../../build/headless');

/*
 * Shows off the LMLayer API, using the full prediction interface.
 * The dummy model (or mock model) is a language model which has 
 * **injectable** suggestions: that is, you, as the tester, have
 * to provide the predictions. The dummy model does not create any
 * suggestions on its own. The dummy model can take in a series
 * of suggestions when loaded and return them sequentially.
 */
describe('LMLayer using dummy model', function () {
  describe('Prediction', function () {
    it('will predict future suggestions (loaded from file)', function () {
      var lmLayer = new LMLayer(capabilities());

      var stripIDs = function(suggestions) {
        suggestions.forEach(function(suggestion) {
          delete suggestion.id;
        });
      }

      // We're testing many as asynchronous messages in a row.
      // this would be cleaner using async/await syntax.
      // Not done yet, as this test case is a slightly-edited copy of the in-browser version.
      return lmLayer.loadModel(
        // We're running headlessly, so the path can be relative to the npm root directory.
        "unit_tests/in_browser/resources/models/simple-dummy.js"
      ).then(function (actualConfiguration) {
        return Promise.resolve();
      }).then(function () {
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[0]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[1]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[2]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[3]);
        lmLayer.shutdown();
        return Promise.resolve();
      });
    });

    it('will predict future suggestions (loaded from raw source)', function () {
      var lmLayer = new LMLayer(capabilities());

      // We're running headlessly, so the path can be relative to the npm root directory.
      let modelCode = fs.readFileSync("./unit_tests/in_browser/resources/models/simple-dummy.js").toString();

      // We're testing many as asynchronous messages in a row.
      // this would be cleaner using async/await syntax.
      // Not done yet, as this test case is a slightly-edited copy of the in-browser version.
      return lmLayer.loadModel(
        modelCode, 'raw'
      ).then(function (actualConfiguration) {
        return Promise.resolve();
      }).then(function () {
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[0]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[1]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[2]);
        return lmLayer.predict(zeroTransform(), emptyContext());
      }).then(function (suggestions) {
        stripIDs(suggestions);
        assert.deepEqual(suggestions, iGotDistractedByHazel()[3]);
        lmLayer.shutdown();
        return Promise.resolve();
      });
    });
  });

  describe('Wordbreaking', function () {
    it('will perform (default) wordbreaking and return word at caret', function () {
      var lmLayer = new LMLayer(capabilities());

      // We're testing many as asynchronous messages in a row.
      // this would be cleaner using async/await syntax.
      // Not done yet, as this test case is a slightly-edited copy of the in-browser version.
      return lmLayer.loadModel(
        // We're running headlessly, so the path can be relative to the npm root directory.
        "unit_tests/in_browser/resources/models/simple-dummy.js"
      ).then(function (actualConfiguration) {
        return Promise.resolve();
      }).then(function () {
        // We'll keep it simple here, as this is primarily an integration test.
        // Functionality is handled in the 'headless' test case 'default-word-breaker.js'.
        let context = { 
          left: 'The quick brown fox jumped', startOfBuffer: true,
{'fraction_non_alphanumeric': 0.11652806652806653, 'fraction_numerical': 0.0016632016632016633, 'mean_word_length': 3.0870858113848767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5528581', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2514, 'n_words': 778}